javax.swing.JTable Java Examples
The following examples show how to use
javax.swing.JTable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SkillPointTableModel.java From pcgen with GNU Lesser General Public License v2.1 | 7 votes |
public static void initializeTable(JTable table) { table.setAutoCreateColumnsFromModel(false); JTableHeader header = table.getTableHeader(); TableColumnModel columns = new DefaultTableColumnModel(); TableCellRenderer headerRenderer = header.getDefaultRenderer(); columns.addColumn(Utilities.createTableColumn(0, "in_level", headerRenderer, false)); columns.addColumn(Utilities.createTableColumn(1, "in_class", headerRenderer, true)); TableColumn remainCol = Utilities.createTableColumn(2, "in_iskRemain", headerRenderer, false); remainCol.setCellRenderer(new BoldNumberRenderer()); columns.addColumn(remainCol); columns.addColumn(Utilities.createTableColumn(3, "in_gained", headerRenderer, false)); table.setDefaultRenderer(Integer.class, new TableCellUtilities.AlignRenderer(SwingConstants.CENTER)); table.setColumnModel(columns); table.setFocusable(false); header.setReorderingAllowed(false); header.setResizingAllowed(false); }
Example #2
Source File: GuiShowGoalDescriptionOverviewAction.java From WorldGrower with GNU General Public License v3.0 | 7 votes |
@Override public void actionPerformed(ActionEvent e) { JFrame frame = new JFrame(); JTable table = new JTable(new GoalModel()); table.setRowHeight(50); table.setBounds(50, 50, 400, 700); frame.add(new JScrollPane(table)); frame.setBounds(100, 100, 500, 800); frame.setVisible(true); }
Example #3
Source File: TransactionsDetailPanel.java From zencash-swing-wallet-ui with MIT License | 6 votes |
private JTable createTransactionsTable(String rowData[][]) throws WalletCallException, IOException, InterruptedException { String columnNames[] = langUtil.getString("transactions.detail.panel.column.names").split(":"); JTable table = new TransactionTable( rowData, columnNames, this.parentFrame, this.clientCaller, this.installationObserver); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); table.getColumnModel().getColumn(0).setPreferredWidth(190); table.getColumnModel().getColumn(1).setPreferredWidth(145); table.getColumnModel().getColumn(2).setPreferredWidth(170); table.getColumnModel().getColumn(3).setPreferredWidth(210); table.getColumnModel().getColumn(4).setPreferredWidth(405); table.getColumnModel().getColumn(5).setPreferredWidth(800); return table; }
Example #4
Source File: NetAdmin.java From nullpomino with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Copy the selected row to clipboard * @param table JTable */ private static void copyTableRowToClipboard(final JTable table) { int row = table.getSelectedRow(); if(row != -1) { String strCopy = ""; for(int column = 0; column < table.getColumnCount(); column++) { Object selectedObject = table.getValueAt(row, column); if(selectedObject instanceof String) { if(column == 0) { strCopy += (String)selectedObject; } else { strCopy += "," + (String)selectedObject; } } } StringSelection ss = new StringSelection(strCopy); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(ss, ss); } }
Example #5
Source File: ListCategoryPane.java From OpERP with MIT License | 6 votes |
public ListCategoryPane() { pane = new JPanel(new MigLayout("fill")); table = new JTable(); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2 && table.getSelectedRow() != -1) { Category category = tableModel.getRow(table .getSelectedRow()); categoryDetailsPane.show(category, getPane()); } } }); final JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.add(scrollPane, "grow"); }
Example #6
Source File: TableRowTransferHandler.java From PyramidShader with GNU General Public License v3.0 | 6 votes |
@Override public boolean importData(TransferHandler.TransferSupport info) { JTable target = (JTable) info.getComponent(); JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation(); int dropIndex = dl.getRow(); int max = table.getModel().getRowCount(); if (dropIndex < 0 || dropIndex > max) { dropIndex = max; } target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); try { Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor); if (rowFrom != -1 && rowFrom != dropIndex) { ((Reorderable)table.getModel()).reorder(rowFrom, dropIndex); if (dropIndex > rowFrom) { dropIndex--; } target.getSelectionModel().addSelectionInterval(dropIndex, dropIndex); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example #7
Source File: LicensesAboutBox.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
private void createLicensesPanel() { JLabel infoText = new JLabel("<html>" + "<b>The table below gives an overview of all 3rd-party licenses used by SNAP " + "and the ESA Toolboxes.<br>" + "The dependencies of other plugins are not considered in this list.</b>" ); JComponent licensesComponent; Path licensesFile = getApplicationHomeDir().toPath().resolve(THIRD_PARTY_LICENSE_DEFAULT_FILE_NAME); try { JTable table = createLicensesTable(licensesFile); licensesComponent = createScrollPane(table); } catch (IOException e) { String msg = "Error: Cloud not read licenses from " + licensesFile.toAbsolutePath().toString(); LOG.log(Level.WARNING, msg, e); JLabel msgLabel = new JLabel(msg); msgLabel.setVerticalAlignment(SwingConstants.TOP); licensesComponent = msgLabel; } add(infoText, BorderLayout.NORTH); add(licensesComponent, BorderLayout.CENTER); setVisible(true); }
Example #8
Source File: TableViewPagePanel.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override protected void initComponents() { final AbstractButton switchToChartButton = ToolButtonFactory.createButton(iconForSwitchToChartButton, false); switchToChartButton.setToolTipText("Switch to Chart View"); switchToChartButton.setName("switchToChartButton"); switchToChartButton.setEnabled(hasAlternativeView()); switchToChartButton.addActionListener(e -> showAlternativeView()); final JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.add(switchToChartButton, BorderLayout.NORTH); buttonPanel.add(getHelpButton(), BorderLayout.SOUTH); add(buttonPanel, BorderLayout.EAST); table = new JTable(); table.removeEditor(); table.setGridColor(Color.LIGHT_GRAY.brighter()); table.addMouseListener(new PagePanel.PopupHandler()); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); final JScrollPane scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); }
Example #9
Source File: JTableLogs.java From mts with GNU General Public License v3.0 | 6 votes |
public void collapseCell(int selected) { final JTable _this = this; //if(lastSelected == selected) { if (_this.getRowHeight(selected) != _this.getRowHeight()) { _this.setRowHeight(selected, _this.getRowHeight()); } else { int maxHeight = _this.getRowHeight(); for (int i = 0; i < _this.getColumnCount(); i++) { Component component = _this.getCellRenderer(selected, i).getTableCellRendererComponent(_this, _this.getValueAt(selected, i), false, true, selected, i); int height = (int) component.getPreferredSize().getHeight(); maxHeight = height > maxHeight ? height : maxHeight; } _this.setRowHeight(selected, maxHeight); } } //lastSelected = selected; }
Example #10
Source File: SwingUtil.java From Repeat with Apache License 2.0 | 6 votes |
/** * Show a list of values to user * @param titles titles of the values * @param values list of values in the according order of the titles */ public static void showValues(String[] titles, String[] values) { if (titles.length == 0 || (titles.length != values.length)) { return; } JTable table = new JTable(); table.setModel(new DefaultTableModel( new Object[][] {}, new String[] {" ", " "} )); SwingUtil.TableUtil.ensureRowNumber(table, titles.length); for (int i = 0; i < titles.length; i++) { table.setValueAt(titles[i], i, 0); table.setValueAt(values[i], i, 1); } JScrollPane mainPanel = new JScrollPane(table); JOptionPane.showMessageDialog(null, mainPanel, "Enter values", JOptionPane.OK_OPTION); }
Example #11
Source File: MainFrameView.java From pgptool with GNU General Public License v3.0 | 6 votes |
private JScrollPane initTableComponent() { table = new JTable(); // Adjust some visual appearence table.setRowHeight(22); // Add listeners selectionModel = new DefaultListSelectionModel(); selectionModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION); selectionModel.addListSelectionListener(rowSelectionListener); table.setSelectionModel(selectionModel); table.addMouseListener(listMouseListener); table.setDefaultRenderer(EncryptBackAction.class, new EncryptBackActionCellRenderer()); table.addMouseListener(encrBackClickHandler); initTableKeyListener(); // Envelope in scrollpane scrollPane = new JScrollPane(); scrollPane.addMouseListener(listMouseListener); scrollPane.setViewportView(table); return scrollPane; }
Example #12
Source File: OptionalValueEditor.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets the table cell editor component. * * @param table the table * @param value the value * @param isSelected the is selected * @param row the row * @param column the column * @return the table cell editor component */ @Override public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int row, int column) { ProcessFunctionParameterValue currentValue = tableModel.getValue(row); if (currentValue.isOptional()) { selectedIndex = row; currentEditor = checkBox; checkBox.setSelected(currentValue.isIncluded()); return checkBox; } else { selectedIndex = -1; currentEditor = null; } return null; }
Example #13
Source File: XTextFieldEditor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { String className; if (table instanceof XTable) { XTable mytable = (XTable) table; className = mytable.getClassName(row); } else { className = String.class.getName(); } try { init(value,Utils.getClass(className)); } catch(Exception e) {} return this; }
Example #14
Source File: TaskListTable.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if( getFoldingModel().isGroupRow( row ) ) { // hasFocus = table.isFocusOwner() && isSelected; } Component res = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if( res instanceof JLabel ) { if( value instanceof FoldingTaskListModel.FoldingGroup ) { FoldingTaskListModel.FoldingGroup fg = (FoldingTaskListModel.FoldingGroup)value; JLabel renderer = (JLabel)res; renderer.setText( fg.getGroup().getDisplayName() + " ("+fg.getTaskCount()+")" ); Icon treeIcon = fg.isExpanded() ? openedIcon : closedIcon; renderer.setIcon( treeIcon ); renderer.setToolTipText( fg.getGroup().getDescription() ); renderer.setHorizontalAlignment( JLabel.LEFT ); if( !isSelected ) renderer.setBackground( getBackgroundColor() ); } } return res; }
Example #15
Source File: TableCellUtilities.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { boolean selected = false; if (value instanceof Boolean) { selected = (Boolean) value; } else if (value instanceof String) { selected = value.equals("true"); } button.setSelected(selected); return button; }
Example #16
Source File: CustomersTableRenderer.java From Hotel-Properties-Management-System with GNU General Public License v2.0 | 6 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // TODO Auto-generated method stub final Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if(isSelected || hasFocus) { cellComponent.setBackground(Color.decode("#10d6d1")); } else { cellComponent.setBackground(row % 2 == 0 ? table.getSelectionBackground() : table.getBackground()); } return cellComponent; }
Example #17
Source File: SystemPropertiesTableHeadRend.java From portecle with GNU General Public License v2.0 | 6 votes |
/** * Returns the rendered header cell for the supplied value and column. * * @param jtSystemProperties The JTable * @param value The value to assign to the cell * @param bIsSelected True if cell is selected * @param iRow The row of the cell to render * @param iCol The column of the cell to render * @param bHasFocus If true, render cell appropriately * @return The rendered cell */ @Override public Component getTableCellRendererComponent(JTable jtSystemProperties, Object value, boolean bIsSelected, boolean bHasFocus, int iRow, int iCol) { // Get header renderer JLabel header = (JLabel) jtSystemProperties.getColumnModel().getColumn(iCol).getHeaderRenderer(); // The headers contain left-aligned text header.setText(value.toString()); header.setHorizontalAlignment(LEFT); header.setBorder(new CompoundBorder(new BevelBorder(BevelBorder.RAISED), new EmptyBorder(0, 5, 0, 5))); return header; }
Example #18
Source File: BooleanRenderer.java From jdal with Apache License 2.0 | 6 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (isSelected) { setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { setForeground(table.getForeground()); setBackground(table.getBackground()); } setSelected((value != null && ((Boolean)value).booleanValue())); if (hasFocus) { setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); } else { setBorder(noFocusBorder); } return this; }
Example #19
Source File: IconTableCellRenderer.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if(value instanceof Icon) { super.getTableCellRendererComponent(table, "", isSelected, hasFocus, row, column); setIcon((Icon)value); if (value instanceof MavenIcon) setToolTipText("Maven Plugin"); else if (value instanceof OpenFileIcon) setToolTipText("Directory Plugin"); else if (value instanceof InvalidIcon) setToolTipText("Invalid Plugin"); return this; } else { return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } }
Example #20
Source File: ComboBoxTableCellEditor.java From netbeans with Apache License 2.0 | 6 votes |
/********************************************************************** * Is the cell editable? If the mouse was pressed at a margin * we don't want the cell to be editable. * * @param evt The event-object. * * @interfaceMethod javax.swing.table.TableCellEditor *********************************************************************/ public boolean isCellEditable (EventObject evt) { this.startEditingEvent = evt; if (evt instanceof MouseEvent && evt.getSource () instanceof JTable) { MouseEvent me = (MouseEvent) evt; JTable table = (JTable) me.getSource (); Point pt = new Point (me.getX (), me.getY ()); int row = table.rowAtPoint (pt); int col = table.columnAtPoint (pt); Rectangle rec = table.getCellRect (row, col, false); if (me.getY () >= rec.y + rec.height || me.getX () >= rec.x + rec.width) { return false; } } return super.isCellEditable (evt); }
Example #21
Source File: CheckboxCellRenderer.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 6 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value != null) { setSelected((Boolean) value); } else { setSelected(false); } if (isSelected) { setBackground(initializer.getConfiguration().getDefaultListSelectionBackground()); setForeground(initializer.getConfiguration().getDefaultListSelectionForeground()); } else { setBackground(initializer.getConfiguration().getDefaultListNonSelectionBackground()); setForeground(initializer.getConfiguration().getDefaultListNonSelectionForeground()); } return this; }
Example #22
Source File: RowHeaderRenderer.java From nextreports-designer with Apache License 2.0 | 5 votes |
RowHeaderRenderer(JTable table) { this.table = table; // this needs to be updated if the LaF changes normalBorder = UIManager.getBorder("TableHeader.cellBorder"); selectedBorder = BorderFactory.createRaisedBevelBorder(); final JTableHeader header = this.table.getTableHeader(); normalFont = header.getFont(); selectedFont = normalFont.deriveFont(normalFont.getStyle() | Font.BOLD); setForeground(header.getForeground()); setBackground(header.getBackground()); setOpaque(true); setHorizontalAlignment(CENTER); }
Example #23
Source File: JTableAccessibleGetLocationOnScreen.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private static void constructInEDT() { String[] columnNames = { "col1", "col2", }; Object[][] data = { { "row1, col1", "row1, col2" }, { "row2, col1", "row2, col2" }, }; frame = new JFrame( "JTable AccessibleTableHeader and AccessibleJTableCell test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); table = new JTable(data, columnNames); frame.add(table); frame.pack(); }
Example #24
Source File: CategoryTotalTable.java From javamoney-examples with Apache License 2.0 | 5 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // Customize look. setLookFor(this, row, isSelected); setToolTipText(buildTooltipText(row)); // Text. if(get(row).getType().isSummary() == true) { setText("<html><b>" + value.toString() + "</b></html>"); } else { setText(value.toString()); } // Alignment. if(column == ROW_COLUMN) { setHorizontalAlignment(SwingConstants.CENTER); } else if(column == CATEGORY_COLUMN || column == GROUP_COLUMN) { setHorizontalAlignment(SwingConstants.LEFT); } else { setHorizontalAlignment(SwingConstants.TRAILING); } return this; }
Example #25
Source File: TestCaseTableDnD.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
@Override public boolean importData(TransferHandler.TransferSupport support) { if (!canImport(support)) { return false; } JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); JTable table = (JTable) support.getComponent(); int row = dl.getRow(); int column = dl.getColumn(); if (row == -1) { return false; } if (dropObject instanceof ObjectRepDnD) { switch (column) { case inputColumn: putInput(table, row); break; case conditionColumn: putRelativeObject(table, row); break; default: putWebObjects(table, row); break; } } else if (dropObject instanceof TestDataDetail) { putTestData(table, row); } else if (dropObject instanceof TestCaseDnD) { putReusables(table, row); } else { return false; } return super.importData(support); }
Example #26
Source File: SwingUtil.java From Repeat with Apache License 2.0 | 5 votes |
public static void clearSelectedTable(JTable table) { int[] columns = table.getSelectedColumns(); int[] rows = table.getSelectedRows(); for (int i = 0; i < rows.length; i++) { for (int j = 0; j < columns.length; j++) { table.setValueAt("", rows[i], columns[j]); } } }
Example #27
Source File: OscarCellRenderers.java From littleluck with Apache License 2.0 | 5 votes |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setText(value != null ? value.toString() : "unknown"); if (!isSelected) { setBackground(rowColors[row % rowColors.length]); } setBorder(null); return this; }
Example #28
Source File: ModelItemNameCellEditor.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 5 votes |
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { model = (ModelItemTableModel<T>) table.getModel(); currentAttribute = model.getRow(row); DefaultTextField theTextfield = (DefaultTextField) getComponent(); theTextfield.setBorder(BorderFactory.createLineBorder(Color.black)); return super.getTableCellEditorComponent(table, value, isSelected, row, column); }
Example #29
Source File: JTableAccessibleGetLocationOnScreen.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void constructInEDT() { String[] columnNames = { "col1", "col2", }; Object[][] data = { { "row1, col1", "row1, col2" }, { "row2, col1", "row2, col2" }, }; frame = new JFrame( "JTable AccessibleTableHeader and AccessibleJTableCell test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); table = new JTable(data, columnNames); frame.add(table); frame.pack(); }
Example #30
Source File: RoomCleaningTableRenderer.java From Hotel-Properties-Management-System with GNU General Public License v2.0 | 5 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); String colrowVal = String.valueOf(value); if(isSelected || hasFocus) { cellComponent.setBackground(Color.decode("#10d6d1")); } else { if(column == 0) { cellComponent.setBackground(Color.decode("#effbad")); } else if (colrowVal.equalsIgnoreCase("CLEAN")) { cellComponent.setBackground(Color.decode("#afe2fb")); } else if (colrowVal.equalsIgnoreCase("DIRTY")) { cellComponent.setBackground(Color.decode("#d24760")); } else if(colrowVal.equalsIgnoreCase("DND")) { cellComponent.setBackground(Color.decode("#ffc300")); } else { cellComponent.setBackground(Color.decode("#f4a0c4")); } } return cellComponent; }