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; }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value == null) { return null; } FileTableLabel label = (FileTableLabel) value; label.setOpaque(false); label.setSelected(isSelected); if (isSelected) { label.setForeground(UIManager.getColor("textHighlightText")); } else { label.setForeground(UIManager.getColor("textText")); } return label; }
private static AbstractAction getEncryptAction(final JTable table) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent me) { try { int col = table.getSelectedColumn(); int row = table.getSelectedRow(); if (col > -1 && row > -1) { String data = table.getValueAt(row, col).toString(); table.setValueAt(TMIntegration.encrypt(data), row, col); } } catch (HeadlessException ex) { Logger.getLogger(TMSettingsControl.class.getName()) .log(Level.SEVERE, ex.getMessage(), ex); } } }; }
/** * Dumps the un-staged and stage models and asserts their content. * * @param unstagedExpected Expected for the un-staged model. * @param indexExpected Expected for the staged model. */ protected void assertTableModels(String unstagedExpected, String indexExpected) { ChangesPanel unstagedChangesPanel = stagingPanel.getUnstagedChangesPanel(); JTable filesTable = unstagedChangesPanel.getFilesTable(); StagingResourcesTableModel uModel = (StagingResourcesTableModel) filesTable.getModel(); // The newly created file is present in the model. ChangesPanel stagedChangesPanel = stagingPanel.getStagedChangesPanel(); JTable stFilesTable = stagedChangesPanel.getFilesTable(); StagingResourcesTableModel stModel = (StagingResourcesTableModel) stFilesTable.getModel(); // The newly created file is present in the model. String ex = "--UNSTAGED--\n" + unstagedExpected + "\n\n--INDEX--\n" + indexExpected; String ac = "--UNSTAGED--\n" + getFlatModelDump(uModel) + "\n\n--INDEX--\n" + getFlatModelDump(stModel); assertEquals(ex, ac); }
public TableExample2(String URL, String driver, String user, String passwd, String query) { JFrame frame = new JFrame("Table"); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd); dt.executeQuery(query); // Create the table JTable tableView = new JTable(dt); JScrollPane scrollpane = new JScrollPane(tableView); scrollpane.setPreferredSize(new Dimension(700, 300)); frame.getContentPane().add(scrollpane); frame.pack(); frame.setVisible(true); }
@Override public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) { final Component c = super.getTableCellEditorComponent(table, value, isSelected, row, column); final JButton button = new JButton("?"); button.setMargin(new Insets(0, 0, 0, 0)); button.setToolTipText(Column.WHO_IS.getLabel()); button.setPreferredSize(new Dimension(Column.WHO_IS.getWidth(), c.getHeight())); button.setMaximumSize(button.getPreferredSize()); if (Env.INSTANCE.getOs() == OS.win) { button.setBorder(null); } button.setEnabled(!_searching); button.addActionListener(e -> { final RoutePoint point = _route.getRoute().get(_table.convertRowIndexToModel(row)); WhoIsPanel.showWhoIsDialog(RouteTablePanel.this, _services, point); if (table.isEditing()) { table.getCellEditor().stopCellEditing(); } _whois.clear(); }); return button; }
void update(MapRule rule,JTable table,int row){ this.rule=rule; int rowHeight=50; int h=table.getRowHeight(row); if(h!=rowHeight){ table.setRowHeight(row, rowHeight); } String name=rule.getName(); if(name==null){ name="无"; }else if(name.trim().equals("")){ name="无"; } label_wan_address.setText("名称: "+rule.name+" 加速端口: "+rule.dst_port); label2.setText("本地端口: "+rule.getListen_port()); }
@Override public void mouseClicked(MouseEvent e) { if (e.getModifiers() == InputEvent.BUTTON3_MASK) { if (!(e.getSource() instanceof JTable)) { return; } tableComponent = (JTable) e.getSource(); tableComponent.requestFocus(); int nx = e.getX(); if (nx > 500) { nx = nx - popup.getSize().width; } popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height); } }
@Override public void actionPerformed(ActionEvent e) { String action = e.getActionCommand(); if (action.equals(Vars.PROP_NEW)) { EstadosCadastro estadosCadastro = new EstadosCadastro(estados); if (VerificaFrame.verificaFrame(estados.getPainel(), estadosCadastro)) { VerificaFrame.exibirFrame(estados.getPainel(), estadosCadastro); estados.addChild(estadosCadastro); } } else if (action.equals(Vars.PROP_REMOVE)) { JTable tabela = estados.getTable(); String sigla = tabela.getValueAt(tabela.getSelectedRow(), 1).toString(); br.com.secharpe.dao.EstadoDAO estDAO = new br.com.secharpe.dao.EstadoDAO(); estDAO.delete(sigla); estados.refreshTable(); } else if (action.equals(Vars.PROP_CLOSE)) { estados.dispose(); } }
/** * deletes all selected columns if it is not present in the <code>exp</code> * List * * @param table the table to DELETE columns * @param exp columns to avoid deleting * @see #deletecol(javax.swing.JTable, int) */ static void deletecols(JTable table, int[] exp) { Integer[] selcols; try { TableColumnModel tcm = table.getColumnModel(); selcols = ArrayUtils.toObject(table.getSelectedColumns()); Arrays.sort(selcols, Collections.reverseOrder()); List<Integer> explist = Ints.asList(exp); for (int i : selcols) { if (!explist.contains(i)) { tcm.removeColumn(tcm.getColumn(i)); } } } catch (Exception e) { Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, e); } }
@Override public boolean canImport(TransferHandler.TransferSupport support) { if (!support.isDrop()) { return false; } JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); if (dl.getColumn() < 1) { return false; } try { if (support.isDataFlavorSupported(ProjectDnD.TESTCASE_FLAVOR)) { dropObject = support.getTransferable().getTransferData(ProjectDnD.TESTCASE_FLAVOR); return true; } else { return false; } } catch (UnsupportedFlavorException | IOException ex) { Logger.getLogger(ScenarioDnD.class.getName()).log(Level.SEVERE, null, ex); return false; } }
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { boolean ascending = false; public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { //System.out.println("Sorting ..."); //int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; //boolean ascending = (shiftPressed == 0); if (column == sortBy) ascending = !ascending; else ascending = true; sorter.sortByColumn(column, ascending); tableView.getTableHeader().updateUI(); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
private static void printWithoutPrintDialog() { final JTable table = createAuthorTable(50); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); try { boolean printAccepted = table.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat("Author Table"), new MessageFormat("Page - {0}"), false, pras, false); closeFrame(); if (!printAccepted) { throw new RuntimeException("User cancels the printer job!"); } } catch (Exception e) { throw new RuntimeException(e); } }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){ Feature feature = featureList.get(row); switch(column){ case ICON_COL: return feature.isSchemaFeature() ? (feature.isRequired() ? requiredIconLabel : optionalIconLabel) : nonSchemaIconLabel; case NAME_COL: prepareCombo(rendererCombo, row, column); rendererCombo.getPreferredSize(); return rendererCombo; case VALUE_COL: prepareCombo(rendererCombo, row, column); return rendererCombo; case DELETE_COL: return deleteButton; default: return null; } }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel l = (JLabel) renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); boolean plotable; if (value != null && value instanceof String) { try { int plotColumn = ((XBTable) table).getPlotColumnIndex(); plotable = (boolean) table.getValueAt(row, plotColumn); } catch(Exception e) { plotable = true; } if (validURL((String)value) && plotable) { l.setText("<html><u><font color=\"blue\">" + l.getText() + "</font></u></html>"); } else { l.setForeground(Color.BLACK); } } return l; }
@Override public void onClick(ActionEvent i_Event) { if ( JavaHelp.isNull(this.getAppFrame().getTableName()) ) { this.getAppFrame().showHintInfo("请先选择要清空的表" ,Color.BLUE); return; } if ( this.getAppFrame().getSelectColCount() <= 1 ) { this.getAppFrame().showHintInfo("请选择查询结果列表中的多行数据" ,Color.BLUE); return; } JTable v_JTable = (JTable)XJava.getObject("xtDataList"); int [] v_RowIndexArr = v_JTable.getSelectedRows(); String v_CMDPuts = this.writeContents(v_JTable ,v_RowIndexArr); ((JTextArea)XJava.getObject("xtPutsInfo")).setText(v_CMDPuts); super.onClick(i_Event); }
private void commitComponent(final Component container) { if (container == null) return; if (container instanceof JTable) { TableCellEditor cellEditor = ((JTable) container) .getCellEditor(); if (cellEditor != null) { try { cellEditor.stopCellEditing(); } catch (Exception e) { try { cellEditor.cancelCellEditing(); } catch (Exception ex) { } } } } }
public QueryBuilderTable( QueryBuilderTableModel model) { super(); super.setModel( model ); Log.getLogger().entering("QueryBuilderTable", "constructor", model); // NOI18N this.setAutoResizeMode (JTable.AUTO_RESIZE_OFF); // This may not be required afterall. We need to keep the size of the cell fixed. this.initColumnSizes(this, model); this.setShowHorizontalLines(false); this.setShowVerticalLines(false); this.setBackground(Color.white); this.setRowHeight(this.getRowHeight() + 2); this.setRowSelectionAllowed (false); this.setTableHeader (null); getAccessibleContext().setAccessibleName(NbBundle.getMessage(QueryBuilderTable.class, "ACS_QueryBuilderTableName")); getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(QueryBuilderTable.class, "ACS_QueryBuilderTableDescription")); }
public static JTable createRawTable(TableModel model) { JTable table = new JTable(model) { @Override public boolean getScrollableTracksViewportHeight() { // fetch the table's parent Container viewport = getParent(); // if the parent is not a viewport, calling this isn't useful if( !(viewport instanceof JViewport) ) { return false; } // return true if the table's preferred height is smaller // than the viewport height, else false return getPreferredSize().height < viewport.getHeight(); } }; return table; }
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { JTable source = (JTable)(e.getSource()); if ( ! source.isEnabled () ) return; _inputTablePopupRow = source.rowAtPoint(new Point (e.getX(), e.getY())); _inputTablePopupColumn = source.columnAtPoint(new Point (e.getX(), e.getY())); // Make sure the row where click occurred is selected. if (_inputTablePopupRow != -1) { source.setRowSelectionInterval (_inputTablePopupRow, _inputTablePopupRow); } // if ( _inputTablePopupColumn != Criteria_COLUMN ) // { // // return without showing popup // return; // } _inputTablePopup.show(e.getComponent(), e.getX(), e.getY()); } }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String simpleClassName = ""; if(value!=null){ String className = (String) value; int simpleNameStart = className.lastIndexOf("."); if(simpleNameStart > -1){ simpleClassName = className.substring(simpleNameStart+1); } } JLabel rendererComponent = new JLabel(); rendererComponent.setText(simpleClassName); rendererComponent.setOpaque(true); GraphGlobals.Colors.setTableCellRendererColors(rendererComponent, row, isSelected); return rendererComponent; }
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { boolean ascending = false; public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { //Util.debug("Sorting ..."); //int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; //boolean ascending = (shiftPressed == 0); if (column == sortBy) ascending = !ascending; else ascending = true; sorter.sortByColumn(column, ascending); tableView.getTableHeader().updateUI(); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value != null) { Date d = (Date) value; setText(def.format(d)); } setForeground(table.getForeground()); setBackground(table.getBackground()); if (isSelected) { setBackground(table.getSelectionBackground()); setForeground(table.getSelectionForeground()); } return this; }
private void evaluateClick(MouseEvent e) { if (e.isPopupTrigger()) { if (e.getComponent() instanceof JTableHeader) { this.headerPopup.show(e.getComponent(), e.getX(), e.getY()); } else { this.row = ((JTable) e.getComponent()).rowAtPoint(e.getPoint()); this.column = ((JTable) e.getComponent()).columnAtPoint(e.getPoint()); if (this.row < 0) { this.panePopup.show(e.getComponent(), e.getX(), e.getY()); return; } int x = (int) this.tableHeader.getHeaderRect(this.mainColumnIndex).getX(); int y = (this.row - 1) * this.getRowHeight() + this.getHeaderHeight(); Dimension d = ((FileTableLabel) this.getValueAt(this.row, this.mainColumnIndex)).getPreferredSize(); Rectangle r = new Rectangle(x, y, Math.min((int) d.getWidth(), this.getColumnModel().getColumn(this.mainColumnIndex).getWidth()), this.getRowHeight(this.row)); if (r.contains(e.getPoint())) { this.tempItem = this.fileList.visibleItemsList.elementAt(this.row); this.tempItem.getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); this.fileList.lastSelected = this.tempItem; } else { this.panePopup.show(e.getComponent(), e.getX(), e.getY()); } } } }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel classNameLabel = new JLabel( ((Class<?>) value).getSimpleName()); table.setRowHeight(row, Math.max(table.getRowHeight(row), (int) classNameLabel.getPreferredSize().getHeight())); TableColumn cm = table.getColumnModel().getColumn(column); cm.setMinWidth(Math.max(cm.getMinWidth(), (int) classNameLabel .getMinimumSize().getWidth())); return classNameLabel; }
public static void pasteFromAbove(JTable table) { int startRow = table.getSelectedRows()[0]; int[] cols = table.getSelectedColumns(); for (int col : cols) { table.setValueAt(table.getValueAt(startRow - 1, col), startRow, col); } }
private Rectangle getHDropLineRect(JTable.DropLocation loc) { if (!loc.isInsertRow()) { return null; } int row = loc.getRow(); int col = loc.getColumn(); if (col >= table.getColumnCount()) { col--; } Rectangle rect = table.getCellRect(row, col, true); if (row >= table.getRowCount()) { row--; Rectangle prevRect = table.getCellRect(row, col, true); rect.y = prevRect.y + prevRect.height; } if (rect.y == 0) { rect.y = -1; } else { rect.y -= 2; } rect.height = 3; return rect; }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); final BasicNode node = (BasicNode) tree.getPathForRow(row) .getLastPathComponent(); c.setEnabled(!node.isSkip()); c.setForeground(EDITABLE_COLOR); return c; }
@Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { pDisj = (ParameterDisjunction)value; DefaultComboBoxModel comboModel = new DefaultComboBoxModel(pDisj.getNames()); combo.setModel(comboModel); combo.setSelectedIndex(pDisj.getSelectedIndex()); return combo; }
public XTable () { super(); @SuppressWarnings("serial") final TableSorter sorter = new TableSorter(); setModel(sorter); sorter.addMouseListenerToHeaderInTable(this); setRowSelectionAllowed(false); setColumnSelectionAllowed(false); setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); }
private void basicSettings() { // disable editing this.table.setDefaultEditor(Object.class, null); // disable dragging column this.table.getTableHeader().setReorderingAllowed(false); // disable multi-row selction this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // this enable scroll panel scroll this.table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { TableCellRenderer def = table.getDefaultRenderer(table.getColumnClass(column)); if (!table.isEnabled()) { isSelected = hasFocus = false; } JComponent c = (JComponent)def.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setEnabled(table.isEnabled()); return c; }
public static void autoSizeTableColumns(JTable table) { TableModel model = table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int maxCellWidth = Integer.MIN_VALUE; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < table.getColumnCount(); i++) { column = table.getColumnModel().getColumn(i); comp = headerRenderer.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width + 10; maxCellWidth = Integer.MIN_VALUE; for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) { TableCellRenderer r = table.getCellRenderer(j, i); comp = r.getTableCellRendererComponent(table, model.getValueAt(j, i), false, false, j, i); cellWidth = comp.getPreferredSize().width; if (cellWidth >= maxCellWidth) { maxCellWidth = cellWidth; } } column.setPreferredWidth(Math.max(headerWidth, maxCellWidth) + 10); } }
public static void removeEmptyRowsFromModel(JTable table, int... excludeColumns) { int rCount = table.getModel().getRowCount(); int cCount = table.getColumnModel().getColumnCount(); stopEditing(table); List<Integer> excludeList = new ArrayList<>(); if (excludeColumns != null && excludeColumns.length > 0) { for (int excludeColumn : excludeColumns) { excludeList.add(excludeColumn); } } try { for (int i = rCount - 1; i >= 0; i--) { Boolean empty = true; for (int j = 0; j < cCount; j++) { if (!excludeList.contains(j)) { if (!Objects.toString(table.getModel().getValueAt(i, j), "").isEmpty()) { empty = false; break; } } } if (empty) { ((DefaultTableModel) table.getModel()).removeRow(i); } } } catch (Exception ex) { Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex); } }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value == null) this.setText(null); else if ((Boolean) value) this.setText(GlobalResourcesManager.getString("Option.Yes")); else this.setText(GlobalResourcesManager.getString("Option.No")); return this; }
@Override public String _getText() { JTable table = (JTable) getComponent(); int rows = table.getRowCount(); int cols = table.getColumnCount(); JSONArray r = new JSONArray(); for (int i = 0; i < rows; i++) { JSONArray c = new JSONArray(); for (int j = 0; j < cols; j++) { c.put(new JTableCellJavaElement(JTableJavaElement.this, i, j)._getText()); } r.put(c); } return r.toString(); }
@Override public void mouseReleased(MouseEvent e) { if (startLocation != null && isInDragOperation) { Object s = e.getSource(); JTable t = (JTable) s; for (Integer[] index : rowsRColumns) { t.setValueAt(startLocation.getData(), index[0], index[1]); } startLocation = null; } rowsRColumns.clear(); isInDragOperation = false; }
private JTable generateTable(InheritedTableModel<?, ?> model, ClientService clientService) { JTable table = new JTable(model); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); TableColumn c2 = table.getColumnModel().getColumn(2); c2.setCellRenderer(new ScriptingTableCellRenderer(model)); c2.setCellEditor(new ScriptingCellEditor(this, clientService, model)); return table; }