private JTable createTabla(DefaultTableModel tableModel) { JTable table = new JTable(); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(false); table.setColumnSelectionAllowed(false); table.setModel(tableModel); table.setRowSelectionAllowed(true); table.getColumnModel().getColumn(0).setResizable(false); table.getColumnModel().getColumn(0).setPreferredWidth(75); table.getColumnModel().getColumn(0).setMinWidth(75); table.getColumnModel().getColumn(0).setMaxWidth(75); table.getColumnModel().getColumn(1).setResizable(false); table.getColumnModel().getColumn(1).setPreferredWidth(125); table.getColumnModel().getColumn(1).setMinWidth(125); table.getColumnModel().getColumn(1).setMaxWidth(125); table.getColumnModel().getColumn(2).setPreferredWidth(50); table.getColumnModel().getColumn(2).setMinWidth(50); table.getColumnModel().getColumn(2).setMaxWidth(50); table.getColumnModel().getColumn(3).setPreferredWidth(85); table.getColumnModel().getColumn(3).setMinWidth(85); table.getColumnModel().getColumn(3).setMaxWidth(85); table.setBounds(10, 420, 350, 125); return table; }
/** * This method initializes jTableTitular * * @return javax.swing.JTable */ private JTable getJTableTitular() { if (jTableTitular == null) { jTableTitular = new JTable(); tablepersonamodel = new TablePersonaModel(); TableSorted tblSorted = new TableSorted(tablepersonamodel); tblSorted.setTableHeader(jTableTitular.getTableHeader()); jTableTitular.setModel(tblSorted); jTableTitular.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jTableTitular.setCellSelectionEnabled(false); jTableTitular.setColumnSelectionAllowed(false); jTableTitular.setRowSelectionAllowed(true); jTableTitular.getTableHeader().setReorderingAllowed(false); ArrayList lst = new ArrayList(); lst.add(new Persona()); ((TablePersonaModel) ((TableSorted) jTableTitular.getModel()).getTableModel()).setData(lst); /* EdicionOperations oper = new EdicionOperations(); try { ArrayList lstVias = oper.obtenerViasCatastro(); ((TableViasCatastroModel)((TableSorted)jTableViasCatastro.getModel()).getTableModel()).setData(lstVias); } catch (DataException e1) { e1.printStackTrace(); } */ } return jTableTitular; }
/** * Constructor de la clase, crea la tabla y de da todas las propiedades para mostrarla en la * aplicacion. */ public PanelHojaCalculo() { modelo = new ModeloTabla(); columnasTabla = new ModeloColumnasTabla(); tabla = new JTable(modelo, columnasTabla); tablaAux = new JTable(modelo, filasTabla); tabla.createDefaultColumnsFromModel(); tablaAux.createDefaultColumnsFromModel(); tabla.setColumnSelectionAllowed(true); tabla.setRowSelectionAllowed(true); tablaAux.setSelectionModel(tabla.getSelectionModel()); tablaAux.setMaximumSize(new Dimension(40, 10000)); tablaAux.setBackground(new Color(238, 238, 238)); // Se puede pasar a true si se quiere seleccionar las filas tablaAux.setEnabled(false); tablaAux.setColumnSelectionAllowed(false); tablaAux.setCellSelectionEnabled(false); viewPort = new JViewport(); viewPort.setView(tablaAux); viewPort.setPreferredSize(tablaAux.getMaximumSize()); tabla.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); tablaAux.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scrollPane = new JScrollPane(tabla); scrollPane.setRowHeader(viewPort); scrollPane.setPreferredSize(new Dimension(790, 500)); add(scrollPane); }
// </editor-fold> private void fillTable(JTable resultTable) { String col[] = {"ID", "Clave", "Nombre", "Estatus"}; tableModel = new DefaultTableModel(col, 0) { @Override public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; // The 0 argument is number rows. resultList .stream() .forEach( (next) -> { tableModel.addRow( new Object[] { next.getProId(), next.getProCode(), next.getProName(), next.getProStatus() }); }); resultTable.setModel(tableModel); resultTable.getColumn("ID").setMinWidth(0); resultTable.getColumn("ID").setMaxWidth(0); resultTable.setColumnSelectionAllowed(false); resultTable.setCellSelectionEnabled(false); resultTable.setRowSelectionAllowed(true); resultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); }
/** * Generates a JTable using results from Assessment data * * @param assessment - Assessment object */ public void makeTable(Assessment assessment) { DefaultTableModel model = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { // Disables all cells from being editable return false; } }; // Assigns column headings boolean isAnonymised = !assessment.getResults().get(0).getCandKey().contains("#"); if (isAnonymised) { model.addColumn("Name"); model.addColumn("Student Number"); } else { model.addColumn("Anon Codes"); } model.addColumn("#Ass"); model.addColumn("Module Code"); model.addColumn("Mark"); model.addColumn("Grade"); table = new JTable(model); table.setFont(new Font("Calibri", Font.BOLD, 14)); // Sets column header look JTableHeader header = table.getTableHeader(); header.setFont(new Font("Calibri", Font.BOLD, 16)); header.setBackground(Color.black); header.setForeground(Color.WHITE); // Sets cell selection to single so only one cell is selected table.setCellSelectionEnabled(true); System.out.println("Making JTable"); // Fetches first assessment and adds results data to model for (Result r : assessment.getResults()) { String name = r.getName(); if (r.getName().equals("")) { name = r.getCandKey(); } if (isAnonymised) { model.addRow( new Object[] { name, r.getCandKey(), r.getAssessment(), r.getModuleCode(), r.getMark(), r.getGrade() }); } else { model.addRow( new Object[] { r.getCandKey(), r.getAssessment(), r.getModuleCode(), r.getMark(), r.getGrade() }); } } table.setPreferredScrollableViewportSize(new Dimension(200, 300)); table.setFillsViewportHeight(true); table.setShowGrid(false); }
private void addNewRowToTable(JTable table) { DefaultTableModel model = (DefaultTableModel) table.getModel(); int rowCount = model.getRowCount(); model.addRow(new Object[] {null, null, null}); rowCount++; table.setCellSelectionEnabled(true); table.changeSelection(rowCount, 0, false, false); table.editCellAt(rowCount, 0); }
public DataTablePanel() { super(new BorderLayout()); tableModel = new DefaultTableModel(); table = new JTable(tableModel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setColumnSelectionAllowed(true); table.setCellSelectionEnabled(true); JScrollPane scroll = new JScrollPane(table); add(scroll, BorderLayout.CENTER); }
private void addMorphismTable() { morphismTable = new JTable(data, columnNames); morphismTable.setGridColor(Color.BLACK); morphismTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); morphismTable.setCellSelectionEnabled(true); morphismTable.setFillsViewportHeight(true); morphismPane = new JScrollPane(morphismTable); morphismPane.setBounds(369, 49, 306, 116); frame.getContentPane().add(morphismPane); }
/** * Delegation to create the Bundle view panel * * @return the JPanel that is responsible for showing the bundle in a tble format */ private JComponent buildBundlePanel() { // build the table table.setColumnSelectionAllowed(true); table.setCellSelectionEnabled(true); table.setAutoCreateColumnsFromModel(true); table.getTableHeader().setUpdateTableInRealTime(false); table.setModel(model); table.setColumnModel(new BundleTableColumnData()); refreshTableData(); table.addMouseListener( new MouseAdapter() { /** @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent) */ @Override public void mousePressed(MouseEvent me) { maybeShowPopup(me); } /** @see java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent) */ @Override public void mouseReleased(MouseEvent me) { maybeShowPopup(me); } /** @param me */ private void maybeShowPopup(MouseEvent me) { // only do for popup menu ctrl if (me.isPopupTrigger() && table.isEnabled()) { Point p = new Point(me.getX(), me.getY()); int rowNum = table.rowAtPoint(p); if (rowNum >= 0 && rowNum < table.getRowCount()) { // create & show the context menu JPopupMenu contextMenu = createContextMenu(rowNum); if (contextMenu != null && contextMenu.getComponentCount() > 0) { contextMenu.show(table, p.x, p.y); } } } } }); // now create the scroll pane to house the table JScrollPane ret = new JScrollPane(); ret.doLayout(); ret.getViewport().setBackground(table.getBackground()); ret.getViewport().add(table); return ret; }
/** * Inicializa la tabla que se utiliza para mostrar los resultados de la bsqueda * * @return */ public JTable getJTable() { if (jTable == null) { // TODO: Poner los titulos de las columnas correspondientes String[] columnNames = { PluginServices.getText(this, "codigo"), PluginServices.getText(this, "nombre"), PluginServices.getText(this, "projected"), PluginServices.getText(this, "datum") }; Object[][] data = {}; dtm = new DefaultTableModel(data, columnNames) { private static final long serialVersionUID = 1L; public boolean isCellEditable(int row, int column) { return false; } /* * metodo necesario para cuando utilizamos tablas ordenadas * ya que sino al ordenar por algun campo no se queda con el orden * actual al seleccionar una fila (non-Javadoc) * @see javax.swing.table.TableModel#getColumnClass(int) */ public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); } }; sorter = new TableSorter(dtm); jTable = new JTable(sorter); sorter.setTableHeader(jTable.getTableHeader()); jTable.setCellSelectionEnabled(false); jTable.setRowSelectionAllowed(true); jTable.setColumnSelectionAllowed(false); jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); TableColumn column = null; for (int i = 0; i < columnNames.length; i++) { column = jTable.getColumnModel().getColumn(i); if (i == 0) { column.setPreferredWidth(80); // code column is shorter } else if (i == 2) { column.setPreferredWidth(50); } else { column.setPreferredWidth(175); } } initializeTable(); } return jTable; }
/** * Creates a panel to display the meta-server. * * @param freeColClient The <code>FreeColClient</code> for the game. * @param connectController The controller responsible for creating new connections. */ public ServerListPanel(FreeColClient freeColClient, ConnectController connectController) { super(freeColClient, new MigLayout("", "", "")); this.connectController = connectController; JButton cancel = new JButton("Cancel"); JScrollPane tableScroll; setCancelComponent(cancel); connect = new JButton(Messages.message("connect")); tableModel = new ServerListTableModel(new ArrayList<ServerInfo>()); table = new JTable(tableModel); DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer() { public Component getTableCellRendererComponent( JTable t, Object o, boolean isSelected, boolean hasFocus, int row, int column) { setOpaque(isSelected); return super.getTableCellRendererComponent(t, o, isSelected, hasFocus, row, column); } }; for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { table.getColumnModel().getColumn(i).setCellRenderer(dtcr); } table.setRowHeight(22); table.setCellSelectionEnabled(false); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableScroll = new JScrollPane(table); table.addNotify(); tableScroll.getViewport().setOpaque(false); tableScroll.getColumnHeader().setOpaque(false); connect.setActionCommand(String.valueOf(CONNECT)); connect.addActionListener(this); cancel.setActionCommand(String.valueOf(CANCEL)); cancel.addActionListener(this); add(tableScroll, "width 400:, height 350:"); add(connect, "newline 20, split 2"); add(cancel, "tag cancel"); setSize(getPreferredSize()); }
/** Create the dialog. */ public USDialog(ActionListener listener) { setIconImages(Simulator.makeIcons()); setBounds(100, 100, 450, 300); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(new BorderLayout(0, 0)); { JComboBox typeBox = new JComboBox(new DefaultComboBoxModel(Relationship.values())); typeEditor = new DefaultCellEditor(typeBox); table = new JTable(new USValuesTableModel()) { // Overridden to return a combobox for duration type @Override public TableCellEditor getCellEditor(int row, int column) { int modelColumn = convertColumnIndexToModel(column); if (modelColumn == 0) return typeEditor; else return super.getCellEditor(row, column); } }; // Make window close on second enter press InputMap map = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); map.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); table.getColumnModel().getColumn(1).setPreferredWidth(10); table.getColumnModel().getColumn(1).setMaxWidth(10); table.doLayout(); // Make single click start editing instead of needing double DefaultCellEditor singleClickEditor = new DefaultCellEditor(new JTextField()); singleClickEditor.setClickCountToStart(1); table.setDefaultEditor(Object.class, singleClickEditor); table.setCellSelectionEnabled(false); JScrollPane scrollPane = new JScrollPane(table); contentPanel.add(scrollPane); } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("OK"); okButton.setActionCommand("OK"); okButton.addActionListener(listener); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } } }
private void initTable() { JTableHeader header = table.getTableHeader(); table.setRowHeight(ROW_HEIGHT); table.setFont(font); header.setFont(font); header.setPreferredSize(new Dimension(header.getWidth(), ROW_HEIGHT)); table.setCellSelectionEnabled(false); table.setOpaque(false); // table.setShowGrid(false); // table.setShowVerticalLines(false); table.setGridColor(gridColor); // 设置表格颜色 setForeground(foreColor); header.setForeground(foreColor); // header.setBackground(headerColor); header.setBorder(new LineBorder(gridColor, 1)); DefaultTableCellRenderer dtr = new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (row % 2 == 0) { setBackground(backColor1); } else if (row % 2 == 1) { setBackground(backColor2); } else setBackground(backColor2); setForeground(foreColor); return super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); } }; dtr.setHorizontalAlignment(JLabel.CENTER); for (int i = 0; i < headerStr.length; i++) { table.getColumn(headerStr[i]).setCellRenderer(dtr); } header.setDefaultRenderer(dtr); }
// This handles the row, column, and cell selection buttons. public void actionPerformed(ActionEvent ie) { // See which button is selected. if (jrbRows.isSelected()) { // Enable row selection. jtabOrders.setColumnSelectionAllowed(false); jtabOrders.setRowSelectionAllowed(true); } else if (jrbColumns.isSelected()) { // Enable column selection. jtabOrders.setColumnSelectionAllowed(true); jtabOrders.setRowSelectionAllowed(false); } else { // Enable cell selection. jtabOrders.setCellSelectionEnabled(true); } }
@SuppressWarnings("unused") private void jbInit() throws Exception { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) data[i][j] = new Integer(i * 10 + j); System.out.println("Header length=" + header[1]); jTable1 = new JTable(data, header); jTable1.setCellSelectionEnabled(true); this.setTitle("Excel Lent JTABLE"); jTable1.setBackground(Color.pink); this.setLayout(borderLayout1); this.setSize(new Dimension(400, 300)); this.setBackground(Color.white); JScrollPane scrollPane = new JScrollPane(jTable1); this.add(scrollPane, BorderLayout.CENTER); // This is the line that does all the magic! ExcelAdapter myAd = new ExcelAdapter(jTable1); }
public static void initializeTable(JTable classLevelTable) { JTableHeader tableHeader = classLevelTable.getTableHeader(); tableHeader.setResizingAllowed(false); tableHeader.setReorderingAllowed(false); TableColumnModel columnModel = new DefaultTableColumnModel(); TableCellRenderer headerRenderer = tableHeader.getDefaultRenderer(); columnModel.addColumn(Utilities.createTableColumn(0, "Level", headerRenderer, false)); columnModel.addColumn(Utilities.createTableColumn(1, "HP", headerRenderer, false)); columnModel.addColumn( Utilities.createTableColumn(2, "Class (All Levels In Class)", headerRenderer, true)); classLevelTable.setColumnModel(columnModel); classLevelTable.setAutoCreateColumnsFromModel(false); classLevelTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); classLevelTable.setFocusable(false); classLevelTable.setCellSelectionEnabled(false); classLevelTable.setRowHeight(20); }
/** * This method initializes jTableBienInmueble * * @return javax.swing.JTable */ private JTable getJTableBienInmueble() { if (jTableBienInmueble == null) { jTableBienInmueble = new JTable(); tablebimodel = new TableBienInmuebleCatastroModel(); TableSorted tblSorted = new TableSorted(tablebimodel); tblSorted.setTableHeader(jTableBienInmueble.getTableHeader()); jTableBienInmueble.setModel(tblSorted); jTableBienInmueble.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jTableBienInmueble.setCellSelectionEnabled(false); jTableBienInmueble.setColumnSelectionAllowed(false); jTableBienInmueble.setRowSelectionAllowed(true); jTableBienInmueble.getTableHeader().setReorderingAllowed(false); ArrayList lst = new ArrayList(); lst.add(new BienInmuebleCatastro()); ((TableBienInmuebleCatastroModel) ((TableSorted) jTableBienInmueble.getModel()).getTableModel()) .setData(lst); /* EdicionOperations oper = new EdicionOperations(); try { ArrayList lst = oper.obtenerFincasExpediente(ex); ((TableBienInmuebleCatastroModel)((TableSorted)jTableBienInmueble.getModel()). getTableModel()).setData(lst); } catch (DataException e1) { e1.printStackTrace(); } */ } return jTableBienInmueble; }
/** * Inicializa todos los elementos del panel y los coloca en su posicion. Carga la tabla y le * asigna los modos que queremos. */ private void inicializaPanel() { tablaRefCatasTabel = new JTable(); identificadores = new String[6]; modelo = new DefaultTableModel() { public boolean isCellEditable(int row, int column) { return false; } }; tablaRefCatasTabel.setModel(modelo); tablaRefCatasTabel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tablaRefCatasTabel.setCellSelectionEnabled(false); tablaRefCatasTabel.setColumnSelectionAllowed(false); tablaRefCatasTabel.setRowSelectionAllowed(true); tablaScrollPanel = new JScrollPane(tablaRefCatasTabel); renombrarComponentes(); this.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); this.add(tablaScrollPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 480, 270)); }
public String selectTableItem() { printTB.setCellSelectionEnabled(true); ListSelectionModel cellSelectionModel = printTB.getSelectionModel(); cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); cellSelectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { int[] selectedRow = printTB.getSelectedRows(); int[] selectedColumns = printTB.getSelectedColumns(); for (int i = 0; i < selectedRow.length; i++) { for (int j = 0; j < selectedColumns.length; j++) { // System.out.println("selectedRow : " + selectedRow[i] + // selectedColumns[0]); save = (String) printTB.getValueAt(selectedRow[i], selectedColumns[j]); } } } }); return save; }
private JComponent getPersonnelTable() { personnelTable = new JTable(personnelModel); personnelTable.setCellSelectionEnabled(false); personnelTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); for (int i = PersonnelTableModel.N_COL - 1; i >= 0; --i) { TableColumn column = personnelTable.getColumnModel().getColumn(i); if (personnelColumns.contains(Integer.valueOf(i))) { column.setPreferredWidth(personnelModel.getColumnWidth(i)); column.setCellRenderer(new CellRenderer()); } else { personnelTable.removeColumn(column); } } personnelTable.setIntercellSpacing(new Dimension(1, 0)); personnelTable.setShowGrid(false); personnelTable.setRowSorter(personnelSorter); JScrollPane pane = new JScrollPane(personnelTable); pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); return pane; }
private void loadView() { // main views mTableModel = new SpreadsheetTableModel(); mTableView = new JTable(mTableModel); mTableView.setRowSelectionAllowed(false); mTableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); mTableView.setFillsViewportHeight(true); mTableView.setDefaultRenderer(String.class, new ColorCellRenderer(TABLE_CELL_COLOR)); mTableView.setDefaultEditor( String.class, new SpreadsheetCellEditor(mTableView.getDefaultEditor(String.class))); mTableView.getSelectionModel().addListSelectionListener(new SpreadsheetSelectionListener()); mTableView .getColumnModel() .getSelectionModel() .addListSelectionListener(new SpreadsheetSelectionListener()); JTable rowHeaderTable = new JTable(new RowHeaderTableModel()); rowHeaderTable.setCellSelectionEnabled(false); rowHeaderTable.setPreferredScrollableViewportSize(new Dimension(50, Integer.MAX_VALUE)); rowHeaderTable.setDefaultRenderer(Object.class, new ColorCellRenderer(ROW_HEADER_COLOR)); mFormulaTextField = new BindableTextField(); mFormulaTextField.setEditable(false); mFormulaTextField.setFocusable(false); JScrollPane scrollView = new JScrollPane(mTableView); scrollView.setRowHeaderView(rowHeaderTable); add(mFormulaTextField, BorderLayout.BEFORE_FIRST_LINE); add(scrollView, BorderLayout.CENTER); // helpers mFileChooser = new SingleExtensionFileChooser(); String extension = SpreadsheetPersistenceManager.SPREADSHEET_FILE_EXTENSION; mFileChooser.setFileExtension(extension, "Spreadsheets file (." + extension + ")"); }
public void showMinerResultsPrecisionAndRecall(MinerResults rets) { DefaultTableModel tmodel = new DefaultTableModel(); // Add columns tmodel.addColumn("时间"); tmodel.addColumn("召回率"); tmodel.addColumn("准确率"); table.setCellSelectionEnabled(false); // table.getColumn("时间").setCellRenderer(new MyTableDateCellRenderer()); // table.getColumn("时间").setCellEditor(new DateEditor(new JTextField())); // Add rows if (rets == null) return; Date d = rets.getDateProcess(); Double[] recall_precision = new Double[2]; recall_precision[0] = rets.getRetSM().getRecallRatio(); recall_precision[1] = rets.getRetSM().getAccuracyRatio(); // 添加至MAP结构中 if (d != null) datas.put(d, recall_precision); // 显示到TABLE中 insertDatas2TableModel(tmodel); table.setModel(tmodel); table.getColumn("时间").setPreferredWidth(200); }
public ElementTableView(TableModel elementTableModel, String title, Icon icon) { this.target = new DummyGDE(); this.name = title; this.icon = icon; setLayout(new BorderLayout()); JTable table = new JTable(elementTableModel) { private static final long serialVersionUID = -2738230330859706440L; public boolean getScrollableTracksViewportWidth() { return getPreferredSize().width < getParent().getWidth(); } }; table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setAutoCreateRowSorter(true); table.setAutoscrolls(true); table.setCellSelectionEnabled(false); table.setRowSelectionAllowed(true); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); add(new JScrollPane(table), BorderLayout.CENTER); }
private void jbInit() throws Exception { panel1.setLayout(borderLayout1); okButton.setText("OK"); okButton.addActionListener(new MimeTypeEditor_okButton_actionAdapter(this)); filtersTable.setRowSelectionAllowed(true); filtersTable.setPreferredSize(new Dimension(418, 200)); filtersTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); filtersTable.setCellSelectionEnabled(true); filtersTable.setColumnSelectionAllowed(false); filtersTable.setModel(m_model); addButton.setToolTipText( "Add a new " + mimeTypeEditorBuilder.getValueName() + " for a MIME type"); addButton.setText("Add"); addButton.addActionListener(new MimeTypeEditor_addButton_actionAdapter(this)); cancelButton.setText("Cancel"); cancelButton.addActionListener(new MimeTypeEditor_cancelButton_actionAdapter(this)); deleteButton.setToolTipText("Delete the currently selected item."); deleteButton.setText("Delete"); deleteButton.addActionListener(new MimeTypeEditor_deleteButton_actionAdapter(this)); upButton.setText("Up"); upButton.addActionListener(new MimeTypeEditor_upButton_actionAdapter(this)); dnButton.setText("Down"); dnButton.addActionListener(new MimeTypeEditor_dnButton_actionAdapter(this)); panel1.setPreferredSize(new Dimension(418, 200)); jScrollPane1.setMinimumSize(new Dimension(200, 80)); jScrollPane1.setOpaque(true); buttonPanel.add(dnButton, null); buttonPanel.add(upButton, null); buttonPanel.add(addButton, null); buttonPanel.add(deleteButton, null); buttonPanel.add(okButton, null); buttonPanel.add(cancelButton, null); getContentPane().add(panel1); panel1.add(buttonPanel, BorderLayout.SOUTH); panel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(filtersTable, null); }
// 设置UI元素的属性 public void compose() { frame.setSize(954, 750); frame.setLocation(200, 50); frame.setResizable(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); // 工具栏 toolBar.add(btDeleteTableData); toolBar.add(tfSqlCommand); toolBar.add(btExecuteSql); toolBar.add(btAbout); frame.add("North", toolBar); // 数据管理层 westJPanel.setLayout(new BorderLayout()); westJPanel.add("North", search); westJPanel.add("Center", awtList); frame.add("West", westJPanel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setShowGrid(true); table.setAutoscrolls(true); table.setDragEnabled(true); table.setCellSelectionEnabled(true); table.setSelectionBackground(new Color(233, 223, 233)); scrollPane.setViewportView(table); frame.add("Center", scrollPane); statusBar.setAlignmentX(JLabel.RIGHT); frame.add("South", statusBar); frame.setVisible(true); }
/** Create the frame. */ public Employee_info() { conn = javaconnect.ConnectrDB(); Update_Table(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(21, 11, 389, 230); contentPane.add(scrollPane); table = new JTable(); table.setColumnSelectionAllowed(true); table.setCellSelectionEnabled(true); table.setShowHorizontalLines(false); table.setShowVerticalLines(false); scrollPane.setViewportView(table); table.setModel(new DefaultTableModel(new Object[][] {}, new String[] {})); }
@Override public void downloadBatch(DownloadBatch_Result result) { table = new JTable(); tableModel = new TableModel(bState, result); table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { cells = bState.cells; JTable target = (JTable) e.getSource(); int row = target.getSelectedRow(); int column = target.getSelectedColumn() - 1; for (ArrayList<Cell> cellRow : cells) { for (Cell cell : cellRow) { if (cell.record == row && cell.field == column) { bState.setSelectedCell(cell); } } } } }); table.addKeyListener( new KeyListener() { @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyReleased(KeyEvent e) { JTable target = (JTable) e.getSource(); int row = target.getSelectedRow(); int column = target.getSelectedColumn() - 1; if (e.getKeyCode() == KeyEvent.VK_TAB) { for (ArrayList<Cell> cellRow : cells) { for (Cell cell : cellRow) { if (cell.record == row && cell.field == column) { bState.setSelectedCell(cell); } } } } } }); table.setModel(tableModel); table.setRowHeight(20); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(true); table.getTableHeader().setReorderingAllowed(false); TableColumnModel columnModel = table.getColumnModel(); for (int i = 0; i < tableModel.getColumnCount(); ++i) { TableColumn column = columnModel.getColumn(i); column.setPreferredWidth(100); } for (int i = 0; i < tableModel.getColumnCount(); ++i) { TableColumn column = columnModel.getColumn(i); column.setCellRenderer(new CellRenderer()); // column.setCellEditor(new CellEditor()); } BoxLayout box = new BoxLayout(this, BoxLayout.Y_AXIS); setLayout(box); add(table.getTableHeader()); add(table); revalidate(); }
/** * Constructor. * * @param unit the unit to display. * @param desktop the main desktop. */ public TabPanelFavorite(Unit unit, MainDesktopPane desktop) { // Use the TabPanel constructor super( Msg.getString("TabPanelFavorite.title"), // $NON-NLS-1$ null, Msg.getString("TabPanelFavorite.tooltip"), // $NON-NLS-1$ unit, desktop); Person person = (Person) unit; // Create Favorite label panel. JPanel favoriteLabelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); topContentPanel.add(favoriteLabelPanel); // Prepare Favorite label JLabel favoriteLabel = new JLabel(Msg.getString("TabPanelFavorite.label"), JLabel.CENTER); // $NON-NLS-1$ favoriteLabelPanel.add(favoriteLabel); // Prepare info panel. JPanel infoPanel = new JPanel(new GridLayout(4, 2, 0, 0)); infoPanel.setBorder(new MarsPanelBorder()); topContentPanel.add(infoPanel, BorderLayout.NORTH); // Prepare main dish name label JLabel mainDishNameLabel = new JLabel(Msg.getString("TabPanelFavorite.mainDish"), JLabel.RIGHT); // $NON-NLS-1$ infoPanel.add(mainDishNameLabel); // Prepare main dish label String mainDish = person.getFavorite().getFavoriteMainDish(); // JLabel mainDishLabel = new JLabel(mainDish, JLabel.RIGHT); // infoPanel.add(mainDishLabel); JTextField mainDishTF = new JTextField(WordUtils.capitalize(mainDish)); mainDishTF.setEditable(false); mainDishTF.setColumns(20); infoPanel.add(mainDishTF); // Prepare side dish name label JLabel sideDishNameLabel = new JLabel(Msg.getString("TabPanelFavorite.sideDish"), JLabel.RIGHT); // $NON-NLS-1$ infoPanel.add(sideDishNameLabel); // Prepare side dish label String sideDish = person.getFavorite().getFavoriteSideDish(); // JLabel sideDishLabel = new JLabel(sideDish, JLabel.RIGHT); // infoPanel.add(sideDishLabel); JTextField sideDishTF = new JTextField(WordUtils.capitalize(sideDish)); sideDishTF.setEditable(false); sideDishTF.setColumns(20); infoPanel.add(sideDishTF); // Prepare dessert name label JLabel dessertNameLabel = new JLabel(Msg.getString("TabPanelFavorite.dessert"), JLabel.RIGHT); // $NON-NLS-1$ infoPanel.add(dessertNameLabel); // Prepare dessert label String dessert = person.getFavorite().getFavoriteDessert(); // JLabel dessertLabel = new JLabel(WordUtils.capitalize(dessert), JLabel.RIGHT); // infoPanel.add(dessertLabel); JTextField dessertTF = new JTextField(WordUtils.capitalize(dessert)); dessertTF.setEditable(false); dessertTF.setColumns(20); infoPanel.add(dessertTF); // Prepare activity name label JLabel activityNameLabel = new JLabel(Msg.getString("TabPanelFavorite.activity"), JLabel.RIGHT); // $NON-NLS-1$ infoPanel.add(activityNameLabel); // Prepare activity label String activity = person.getFavorite().getFavoriteActivity(); JTextField activityTF = new JTextField(WordUtils.capitalize(activity)); activityTF.setEditable(false); activityTF.setColumns(20); infoPanel.add(activityTF); // JLabel activityLabel = new JLabel(WordUtils.capitalize(activity), JLabel.RIGHT); // infoPanel.add(activityLabel); // Create label panel. JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); centerContentPanel.add(labelPanel, BorderLayout.NORTH); // Create preference label JLabel label = new JLabel("Preferences"); labelPanel.add(label); // Create scroll panel JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(new MarsPanelBorder()); scrollPane.getVerticalScrollBar().setUnitIncrement(10); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); centerContentPanel.add(scrollPane, BorderLayout.CENTER); // Create skill table tableModel = new PreferenceTableModel(person); JTable table = new JTable(tableModel); table.setPreferredScrollableViewportSize(new Dimension(225, 100)); table.getColumnModel().getColumn(0).setPreferredWidth(100); table.getColumnModel().getColumn(1).setPreferredWidth(30); table.setCellSelectionEnabled(false); table.setDefaultRenderer(Integer.class, new NumberCellRenderer()); // 2015-06-08 Added sorting table.setAutoCreateRowSorter(true); table.getTableHeader().setDefaultRenderer(new MultisortTableHeaderCellRenderer()); // 2015-06-08 Added setTableStyle() TableStyle.setTableStyle(table); scrollPane.setViewportView(table); }
public void initializeGUI() { setTitle(frameTitle); setSize(detailsFrameXsize, detailsFrameYsize); setLocation(detailsFrameXlocation, detailsFrameYlocation); treemodel = new DefaultTreeModel(new DefaultMutableTreeNode("LSM File Information")); detailsTree = new JTree(treemodel); detailsTree.putClientProperty("JTree.lineStyle", "Angled"); detailsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); detailsTree.setShowsRootHandles(true); tablemodel = new TreeTableModel(); table = new JTable(tablemodel); table.setCellSelectionEnabled(true); JScrollPane treepane = new JScrollPane(detailsTree); JScrollPane detailspane = new JScrollPane(table); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treepane, detailspane); splitPane.setBorder(null); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(300); Dimension minimumSize = new Dimension(WIDTH, HEIGHT - 50); treepane.setMinimumSize(minimumSize); detailspane.setMinimumSize(minimumSize); exitButton = new JButton(new ImageIcon(getClass().getResource("images/exit.png"))); exitButton.setToolTipText("Close this window"); searchButton = new JButton(new ImageIcon(getClass().getResource("images/find.png"))); searchButton.setToolTipText("Find tag, property or value"); filterButton = new JToggleButton(new ImageIcon(getClass().getResource("images/filter.png"))); filterButton.setToolTipText("Filter unused tags"); dumpButton = new JButton(new ImageIcon(getClass().getResource("images/dump.png"))); dumpButton.setToolTipText("Dump data to textwindow, saving to text file is possible"); xmlButton = new JButton(new ImageIcon(getClass().getResource("images/xml.png"))); xmlButton.setToolTipText("Dump xml data to textwindow, saving to text file is possible"); searchTF = new JTextField(""); detailsTreePopupMenu = new JPopupMenu(); expandAllItem = new JMenuItem("Expand all", new ImageIcon(getClass().getResource("images/plus.png"))); collapseAllItem = new JMenuItem("Collapse all", new ImageIcon(getClass().getResource("images/minus.png"))); filterCBItem = new JCheckBoxMenuItem( "Filtered", new ImageIcon(getClass().getResource("images/filter.png"))); detailsTreePopupMenu.add(expandAllItem); detailsTreePopupMenu.add(collapseAllItem); detailsTreePopupMenu.add(new JSeparator()); detailsTreePopupMenu.add(filterCBItem); detailsTreePopupMenu.setOpaque(true); detailsTree.add(detailsTreePopupMenu); detailsTree.setExpandsSelectedPaths(true); toolBar = new JToolBar(); toolBar.add(exitButton); toolBar.add(dumpButton); toolBar.add(xmlButton); toolBar.add(filterButton); toolBar.add(new JSeparator()); toolBar.add(new JLabel(" Search: ")); toolBar.add(searchTF); toolBar.add(searchButton); getContentPane().setLayout(new BorderLayout()); getContentPane().add(toolBar, BorderLayout.NORTH); getContentPane().add(splitPane, BorderLayout.CENTER); // filterCBItem.setSelected(true); // filterButton.setSelected(true); pack(); centerWindow(); setListeners(); }
public TableViewComponent() { super(); setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(12, 12, 12, 12), BorderFactory.createLoweredBevelBorder())); table = new JTable(); table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(false); table.setCellSelectionEnabled(true); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListSelectionListener selectionListener = new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } ListSelectionModel rowSelections = table.getSelectionModel(); ListSelectionModel columnSelections = table.getColumnModel().getSelectionModel(); if (rowSelections.isSelectionEmpty() || columnSelections.isSelectionEmpty()) { // no new selection -> nothing has changed return; } int rowIndex = rowSelections.getLeadSelectionIndex(); int columnIndex = columnSelections.getLeadSelectionIndex(); int modelRowIndex = table.convertRowIndexToModel(rowIndex); int modelColumnIndex = table.convertColumnIndexToModel(columnIndex); if (selectedNode != null) { selectedNode.setHereTooSelected(false); } final NodeWrapper newSelection = (NodeWrapper) table.getModel().getValueAt(modelRowIndex, modelColumnIndex); newSelection.setHereTooSelected(true); selectedNode = newSelection; table.invalidate(); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { table.repaint(); } }); } }; table.getSelectionModel().addListSelectionListener(selectionListener); table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener); table.setAutoCreateRowSorter(false); table.setFillsViewportHeight(true); table.setGridColor(COLOR_GRID_LINES); table.setShowGrid(false); table.setShowHorizontalLines(true); // 0px between cells in the same row; 1px between rows table.setIntercellSpacing(new Dimension(0, 1)); FontMetrics metrics = table.getFontMetrics(table.getFont()); int rowHeight = 2 * metrics.getMaxAscent() + 2 * metrics.getMaxDescent() + metrics.getLeading(); table.setRowHeight(rowHeight); setViewportView(table); // context menus + double-click for chain nav table.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 2) { return; } NodeWrapper node = getNodeWrapperAtPoint(e); if (node != null) { fireNodeSelected(node); } } @Override public void mousePressed(MouseEvent e) { handlePopup(e); } @Override public void mouseReleased(MouseEvent e) { handlePopup(e); } private void handlePopup(MouseEvent e) { if (!e.isPopupTrigger()) { return; } NodeWrapper node = getNodeWrapperAtPoint(e); if (node != null) { popup.setNodeWrapper(node); popup.show(table, e.getX(), e.getY()); } } private NodeWrapper getNodeWrapperAtPoint(MouseEvent e) { int viewColumn = table.columnAtPoint(e.getPoint()); int viewRow = table.rowAtPoint(e.getPoint()); if (viewColumn == -1 || viewRow == -1) { // this means that we have an invalid point return null; } NodeWrapper node = (NodeWrapper) table.getValueAt(viewRow, viewColumn); return node; } }); }