public TableCellEditor getCellEditor(int row, int col) { TableCellEditor ed; if(col == TREE_COLUMN) { treeEditor.setBaseEditor(super.getCellEditor(row, col)); ed = treeEditor; } else { ed = super.getCellEditor(row, col); } // FIX does not help: first typed symbol gets eaten // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4222149 if(ed instanceof DefaultCellEditor) { ((DefaultCellEditor)ed).setClickCountToStart(0); } return ed; }
@Override public TableCellEditor getCellEditor(int row, int column) { if (column == 2){ if (getModel() instanceof TableClassNamesModel) { TableClassNamesModel model = (TableClassNamesModel)getModel(); Table table = model.getTableAt(row); DisabledReason dr = table.getDisabledReason(); boolean existing = dr instanceof Table.ExistingDisabledReason; if (existing){ return new DefaultCellEditor(new JComboBox(new UpdateType[]{UpdateType.UPDATE, UpdateType.RECREATE})); } else { return new DefaultCellEditor(new JComboBox(new UpdateType[]{UpdateType.NEW})); } } } return super.getCellEditor(row, column); }
@Override public TableCellEditor getCellEditor(int row, int column) { if(showParamTypes) { String paramName = (String) tableModel.getValueAt(row, 0); Class type = (column == 2) ? (Class) tableModel.getValueAt(row, 1) : Boolean.class; if (Enum.class.isAssignableFrom(type)) { JComboBox combo = new JComboBox(type.getEnumConstants()); return new DefaultCellEditor(combo); } else if (type == Boolean.class || type == Boolean.TYPE) { JCheckBox cb = new JCheckBox(); cb.setHorizontalAlignment(JLabel.CENTER); cb.setBorderPainted(true); return new DefaultCellEditor(cb); } else if (paramName.toLowerCase().contains(Constants.PASSWORD)) { return new DefaultCellEditor(new JPasswordField()); } } return super.getCellEditor(row, column); }
@Override public TableCellEditor getCellEditor(int row, int column) { List<String> usedTypes = new LinkedList<String>(); for (int i = 0; i < Ontology.VALUE_TYPE_NAMES.length; i++) { if ((i != Ontology.ATTRIBUTE_VALUE) && (i != Ontology.FILE_PATH) && (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(i, Ontology.DATE_TIME))) { usedTypes.add(Ontology.ATTRIBUTE_VALUE_TYPE.mapIndex(i)); } } String[] valueTypes = new String[usedTypes.size()]; int vCounter = 0; for (String type : usedTypes) { valueTypes[vCounter++] = type; } JComboBox typeBox = new JComboBox(valueTypes); typeBox.setBackground(javax.swing.UIManager.getColor("Table.cellBackground")); return new DefaultCellEditor(typeBox); }
@Override public void gotFocus() { this.sync(); this.refreshComponents(); stTable.update(); stTable.updateStructure(); StationCombo = new ComboBoxCell(stationNames); JComboBox stationBox = new JComboBox(stationNames); stationBox.setEditable(false); ComboBoxRenderer renderer = new ComboBoxRenderer(stationBox); renderer.setColors(colors); renderer.setStrings(stationNames); stationBox.setRenderer(renderer); stationEditor = new DefaultCellEditor(stationBox); }
public void setUpSportColumn(JTable table, TableColumn sportColumn) { // Set up the editor for the sport cells. JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); // Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); sportColumn.setCellRenderer(renderer); }
public void setupVariationFunctionComboBoxColumn() { if (parentController.getMainPanel().getVariationPerParameterTable().getColumnModel() != null) { JComboBox comboBox = new JComboBox(); JComboBox comboBoxRender = new JComboBox(); this.populateTypeComboBox(comboBox); this.populateTypeComboBox(comboBoxRender); TableColumn column = parentController.getMainPanel() .getVariationPerParameterTable() .getColumnModel() .getColumn( VariationPerParameterTableModel.COLUMN_VARIATION_TYPE); column.setCellEditor(new DefaultCellEditor(comboBox)); TableRenderer cellRenderer = new TableRenderer(comboBoxRender); column.setCellRenderer(cellRenderer); } }
protected void createEditors() { setDefaultEditor(Boolean.class, new DefaultCellEditor(new JCheckBox()) { /** * */ private static final long serialVersionUID = 1L; @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { Component c = super.getTableCellEditorComponent(table, value, isSelected, row, column); if (value instanceof Boolean) { c.setBackground(Color.WHITE); c.setVisible(false); } return c; } }); }
private TableCellEditor createBaseQualifierEditor() { List<Qualifier> qualifiers = engine.getQualifiers(); Collections.sort(qualifiers, new Comparator<Qualifier>() { @Override public int compare(Qualifier o1, Qualifier o2) { return collator.compare(o1.getName(), o2.getName()); } }); JComboBox box = new JComboBox(); box.addItem(null); for (Qualifier qualifier : qualifiers) box.addItem(qualifier); return new DefaultCellEditor(box); }
public Test6505027(JFrame main) { Container container = main; if (INTERNAL) { JInternalFrame frame = new JInternalFrame(); frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT); frame.setVisible(true); JDesktopPane desktop = new JDesktopPane(); desktop.add(frame, new Integer(1)); container.add(desktop); container = frame; } if (TERMINATE) { this.table.putClientProperty(KEY, Boolean.TRUE); } TableColumn column = this.table.getColumn(COLUMNS[1]); column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS))); container.add(BorderLayout.NORTH, new JTextField()); container.add(BorderLayout.CENTER, new JScrollPane(this.table)); }
public void fillPlan(SelfSituation plan) { this.plan = plan; // запомним старые значения на случай отката oldValues.clear(); for (SelfService service : plan.getSelfservices()) { if (service.isFlexy()) { oldValues.put(service.getId(), service.getPriority()); } } tablePlan.setModel(new FlexPriorityMableModel(plan)); JComboBox<String> cb = new JComboBox<>(); /* cb.addItem(Uses.get_COEFF_WORD().get(Uses.SERVICE_REMAINS)); cb.addItem(Uses.get_COEFF_WORD().get(Uses.SERVICE_NORMAL)); cb.addItem(Uses.get_COEFF_WORD().get(Uses.SERVICE_VIP)); */ Uses.get_COEFF_WORD().values().forEach(pr -> cb.addItem(pr)); TableCellEditor editor = new DefaultCellEditor(cb); TableColumnModel cm = tablePlan.getColumnModel(); TableColumn tc = cm.getColumn(1); tc.setCellEditor(editor); tablePlan.setDefaultRenderer(SelfService.class, new FlexPriorityCell()); }
public void editingStopped(ChangeEvent e) { TrackModel model = (TrackModel) getModel(); int row = getSelectedRow(); int col = getSelectedColumn(); try { DefaultCellEditor ce = (DefaultCellEditor) e.getSource(); JTextField c = (JTextField) ce.getComponent(); // Extract value from cell and convert to double. double time = Double.valueOf(c.getText()).doubleValue(); Track track = model.getTrackList().getTrack(row); // Playing time can not be longer than duration. time = Math.min(time, track.getDuration().getSeconds()); model.setPlayingTime(row, time); } catch (Exception ex) { ex.printStackTrace(); System.out.println(ex.getClass().getName()); } }
private TableColumn createColumn(int colIndex, boolean defaultWidth) { TableColumn column = new SpreadsheetColumn(defaultWidth); column.setModelIndex(colIndex); column.setHeaderValue(getColumnHeaderValue(colIndex)); column.setHeaderRenderer(renderer); // TASK:UNEDITCOM String name = getColumnId(colIndex); if (name.equals(propertiesCommentsColumn)) { column.setCellEditor(new DefaultCellEditor(new JTextField()){ public boolean isCellEditable(EventObject anEvent) { return false; } }); } return column; }
public void setSkeleton(SkeletonBean skel) { m_name.setText(skel.getShortName()); m_description.setText(skel.getDescription()); m_categoryName.setText(skel.getResourceCategory()); m_jarId.setText(new Integer(skel.getResourceJarId()).toString()); m_propsId.setText(new Integer(skel.getResourcePropsId()).toString()); m_exeName.setText(skel.getExecutableName()); m_cbDebug.setSelected(skel.isDebug()); m_model = new SkeletonPropertyTableModel(skel.getSkeletonProperties()); TableColumn type = m_propTable.getColumnModel().getColumn(3); JComboBox typeCombo = new JComboBox(); typeCombo.addItem(SkeletonProperty.TYPE_STRING); typeCombo.addItem(SkeletonProperty.TYPE_TEXTAREA); typeCombo.addItem(SkeletonProperty.TYPE_BOOLEAN); type.setCellEditor(new DefaultCellEditor(typeCombo)); m_propTable.setModel(m_model); }
ChannelRoutingTable() { super(new ChannelRoutingTableModel()); JComboBox cb = new JComboBox(); int devId = channel.getAudioOutputDevice(); AudioDeviceModel adm = CC.getSamplerModel().getAudioDeviceById(devId); if(adm == null) { setEnabled(false); } else { int chns = adm.getDeviceInfo().getAudioChannelCount(); for(Integer i = 0; i < chns; i++) cb.addItem(i); } TableColumn column = getColumnModel().getColumn(1); column.setCellEditor(new DefaultCellEditor(cb)); }
ChannelRoutingTable() { super(new ChannelRoutingTableModel()); JComboBox cb = new JComboBox(); int devId = channelModel.getChannelInfo().getAudioOutputDevice(); AudioDeviceModel adm = CC.getSamplerModel().getAudioDeviceById(devId); int chns; if(adm == null) { chns = channelModel.getChannelInfo().getAudioOutputChannels(); } else { chns = adm.getDeviceInfo().getAudioChannelCount(); } for(Integer i = 0; i < chns; i++) cb.addItem(i); TableColumn column = getColumnModel().getColumn(1); column.setCellEditor(new DefaultCellEditor(cb)); }
/** * setDefaultTableEditorsClicks, This sets the number of clicks required to start the default * table editors in the supplied table. Typically you would set the table editors to start after * 1 click or 2 clicks, as desired. * * The default table editors of the table editors that are supplied by the JTable class, for * Objects, Numbers, and Booleans. Note, the editor which is used to edit Objects, is the same * editor used for editing Strings. */ public static void setDefaultTableEditorsClicks(JTable table, int clickCountToStart) { TableCellEditor editor; editor = table.getDefaultEditor(Object.class); if (editor instanceof DefaultCellEditor) { ((DefaultCellEditor) editor).setClickCountToStart(clickCountToStart); } editor = table.getDefaultEditor(Number.class); if (editor instanceof DefaultCellEditor) { ((DefaultCellEditor) editor).setClickCountToStart(clickCountToStart); } editor = table.getDefaultEditor(Boolean.class); if (editor instanceof DefaultCellEditor) { ((DefaultCellEditor) editor).setClickCountToStart(clickCountToStart); } }
private void refreshTable() { JCheckBox checkBox = new javax.swing.JCheckBox(); String[] tableTitle = {"", "Tag", "Value"}; DefaultTableModel tableModel = new DefaultTableModel(tagsOfTable, tableTitle) { Class[] types = new Class[]{ java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class }; @Override public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }; jTableTags.setModel(tableModel); jTableTags.getColumn("").setPreferredWidth(5); jTableTags.getColumn("Tag").setPreferredWidth(150); jTableTags.getColumn("Value").setPreferredWidth(150); checkBox.setAlignmentX(0); jTableTags.getColumn("").setCellEditor(new DefaultCellEditor(checkBox)); }
/** * Set the custom editors for combo boxes. This method also sets one * custom renderer. */ void setCustomEditors() { TableColumnModel cm = table.getColumnModel(); // Set combo-box based editor for icons (note that no custom // renderer is needed for JComboBox to work with icons. JComboBox combo0 = new JComboBox(icons); cm.getColumn(1).setCellEditor(new DefaultCellEditor(combo0)); // Set the simple combo box editor for the third column: JComboBox combo1 = new JComboBox(sides); cm.getColumn(2).setCellEditor(new DefaultCellEditor(combo1)); // Set the editable combo box for the forth column: JComboBox combo2 = new JComboBox(sides); combo2.setEditable(true); cm.getColumn(3).setCellEditor(new DefaultCellEditor(combo2)); SliderCell scrollView = new SliderCell(); cm.getColumn(4).setCellEditor(scrollView); cm.getColumn(4).setCellRenderer(scrollView); table.setColumnModel(cm); }
/** * For the double click, start the cell editor. */ public void mouseClicked(MouseEvent e) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int col = table.columnAtPoint(p); if (table.isCellEditable(row, col)) { // If the cell editor is the default editor, we request the // number of the required clicks from it. Otherwise, // require two clicks (double click). TableCellEditor editor = table.getCellEditor(row, col); if (editor instanceof DefaultCellEditor) { DefaultCellEditor ce = (DefaultCellEditor) editor; if (e.getClickCount() < ce.getClickCountToStart()) return; } table.editCellAt(row, col); } }
@Override public TableCellEditor getCellEditor(int row, int column) { List<String> usedTypes = new LinkedList<String>(); for (int i = 0; i < Ontology.VALUE_TYPE_NAMES.length; i++) { if ((i != Ontology.ATTRIBUTE_VALUE) && (i != Ontology.FILE_PATH) && (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(i, Ontology.DATE_TIME))) { usedTypes.add(Ontology.ATTRIBUTE_VALUE_TYPE.mapIndex(i)); } } String[] valueTypes = new String[usedTypes.size()]; int vCounter = 0; for (String type : usedTypes) { valueTypes[vCounter++] = type; } JComboBox<String> typeBox = new JComboBox<>(valueTypes); typeBox.setBackground(javax.swing.UIManager.getColor("Table.cellBackground")); return new DefaultCellEditor(typeBox); }
/** * Instantiates a new member table. * * @param model The member table model to use. * @param baseTypes The list of base types in the current type system to be used in the cell * editor of the types column. */ public MemberTable(final MemberTableModel model, final List<BaseType> baseTypes) { super(model); setSurrendersFocusOnKeystroke(true); addMouseListener(new MemberTableMouseListener(this)); // Base types are edited via a combobox. getColumnModel().getColumn(MemberTableModel.TYPE_COLUMN).setCellEditor(new DefaultCellEditor( new TypeComboBox(new TypeListModel(baseTypes, new TypeListModel.PrototypesFilter())))); // Make sure base types are rendered with their name only, not their toString method. getColumnModel().getColumn(MemberTableModel.TYPE_COLUMN) .setCellRenderer(new BaseTypeCellRenderer()); // Force the table to consume all available space in the parent view port so we get click // events to trigger the popup menu even if the table is empty. setFillsViewportHeight(true); // Assign custom renderers that set the background color of rows to red if these rows represent // an invalid constellation of members. getColumnModel().getColumn(MemberTableModel.NAME_COLUMN) .setCellRenderer(new InvalidRowTableCellRenderer()); getColumnModel().getColumn(MemberTableModel.INDEX_COLUMN) .setCellRenderer(new InvalidRowTableCellRenderer()); }
public void setUpSportColumn(JTable table, TableColumn sportColumn) { //Set up the editor for the sport cells. JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); //Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); sportColumn.setCellRenderer(renderer); }
public UpdateSummaryTable(List<ArtifactStatus> artifactStatus, UpdateSummaryTableModel model) { super(model); _model = model; _artifacts = artifactStatus; setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); getTableHeader().setResizingAllowed(true); getTableHeader().setReorderingAllowed(true); setAutoCreateColumnsFromModel(false); setAutoResizeMode(AUTO_RESIZE_LAST_COLUMN); final TableColumnModel tcm = new DefaultTableColumnModel(); JComboBox _actionComboBox = new JComboBox(); for (int i = 0; i < model.getColumnCount(); ++i) { final TableColumn col = new TableColumn(i, model.getColumnWidth(i)); col.setHeaderValue(model.getColumnName(i)); if (i == 3) { col.setCellEditor(new DefaultCellEditor(initCbo(_actionComboBox))); } tcm.addColumn(col); } setColumnModel(tcm); initPopup(); }
EditorPaneCellEditor() { super(new JTextField()); final JEditorPane textArea = new JEditorPane(); textArea.setEditable(false); textArea.setContentType("text/html"); final JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setBorder(null); editorComponent = scrollPane; delegate = new DefaultCellEditor.EditorDelegate() { private static final long serialVersionUID = 5746645959173385516L; @Override public void setValue(final Object value) { textArea.setText((value != null) ? value.toString() : ""); } @Override public Object getCellEditorValue() { return textArea.getText(); } }; }
public GranteeTable(GranteeTableModel granteeTableModel) { super(); sorter = new TableSorter(granteeTableModel); this.setModel(sorter); sorter.setTableHeader(this.getTableHeader()); getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); getSelectionModel().addListSelectionListener(this); DefaultCellEditor groupCellEditor = new DefaultCellEditor(groupGranteeComboBox); groupCellEditor.setClickCountToStart(2); setDefaultEditor(GroupGrantee.class, groupCellEditor); setDefaultRenderer(GroupGrantee.class, new DefaultTableCellRenderer() { private static final long serialVersionUID = 4938391147702620699L; public Component getTableCellRendererComponent(JTable arg0, Object value, boolean arg2, boolean arg3, int arg4, int arg5) { GroupGrantee groupGrantee = (GroupGrantee) value; return super.getTableCellRendererComponent(arg0, groupGrantee.getIdentifier(), arg2, arg3, arg4, arg5); } }); DefaultCellEditor permissionCellEditor = new DefaultCellEditor(permissionComboBox); permissionCellEditor.setClickCountToStart(2); setDefaultEditor(Permission.class, permissionCellEditor); }
public static void setHorizontalAlignment(Object x, int alignment) { if(x instanceof JLabel) { ((JLabel)x).setHorizontalAlignment(alignment); } else if(x instanceof JTextField) { ((JTextField)x).setHorizontalAlignment(alignment); } else if(x instanceof JCheckBox) { ((JCheckBox)x).setHorizontalAlignment(alignment); } else if(x instanceof DefaultCellEditor) { Component c = ((DefaultCellEditor)x).getComponent(); setHorizontalAlignment(c, alignment); } else { Log.ex("no horizontal alignment for " + x); } }
/** * Tries its best to <code>updateUI</code> of the potential * <code>TableCellEditor</code>. * * @param maybeEditor the potential editor. */ private void updateEditorUI(Object maybeEditor) { // maybe null or proxyValue if (!(maybeEditor instanceof TableCellEditor)) return; // super handled this if ((maybeEditor instanceof JComponent) || (maybeEditor instanceof DefaultCellEditor)) return; // custom editors might balk about fake rows/columns try { Component comp = ((TableCellEditor) maybeEditor) .getTableCellEditorComponent(this, null, false, -1, -1); if (comp != null) { SwingUtilities.updateComponentTreeUI(comp); } } catch (Exception e) { // ignore - can't do anything } }
/** * @param editor * */ private void updateEditorUI(TableCellEditor editor) { if (editor == null) return; // internal knowledge of core table - already updated if ((editor instanceof JComponent) || (editor instanceof DefaultCellEditor)) return; try { Component comp = editor .getTableCellEditorComponent(null, null, false, -1, -1); if (comp != null) { SwingUtilities.updateComponentTreeUI(comp); } } catch (Exception e) { // can't do anything - renderer can't cope with off-range cells } }
/** * test that transferFocus methods try to stop edit. * * Here: do nothing if !isTerminateEditOnFocusLost. * */ @Test public void testFocusTransferBackwardTerminateEditFalse() { JXTable table = new JXTable(10, 2); table.setTerminateEditOnFocusLost(false); DefaultCellEditor editor = new DefaultCellEditor(new JTextField()); // need to replace generic editor - which fires twice table.setDefaultEditor(Object.class, editor); table.editCellAt(0, 0); // sanity assertTrue(table.isEditing()); CellEditorReport report = new CellEditorReport(); table.getCellEditor().addCellEditorListener(report); table.transferFocusBackward(); assertTrue("table must be editing", table.isEditing()); assertEquals("", 0, report.getEventCount()); }
/** * test that transferFocus methods try to stop edit. * * Here: do nothing if !isTerminateEditOnFocusLost. * */ @Test public void testFocusTransferForwardTerminateEditFalse() { JXTable table = new JXTable(10, 2); table.setTerminateEditOnFocusLost(false); DefaultCellEditor editor = new DefaultCellEditor(new JTextField()); // need to replace generic editor - which fires twice table.setDefaultEditor(Object.class, editor); table.editCellAt(0, 0); // sanity assertTrue(table.isEditing()); CellEditorReport report = new CellEditorReport(); table.getCellEditor().addCellEditorListener(report); table.transferFocus(); assertTrue("table must be editing", table.isEditing()); assertEquals("", 0, report.getEventCount()); }
/** * test that transferFocus methods try to stop edit. * * Here: respect false on backward. * */ @Test public void testFocusTransferBackwardStopEditingFalse() { JXTable table = new JXTable(10, 2); DefaultCellEditor editor = new DefaultCellEditor(new JTextField()){ @Override public boolean stopCellEditing() { return false; } }; // need to replace generic editor - which fires twice table.setDefaultEditor(Object.class, editor); table.editCellAt(0, 0); // sanity assertTrue(table.isEditing()); CellEditorReport report = new CellEditorReport(); table.getCellEditor().addCellEditorListener(report); table.transferFocusBackward(); assertTrue("table must be editing", table.isEditing()); assertEquals("", 0, report.getEventCount()); }
/** * test that transferFocus methods try to stop edit. * * Here: respect editor false on forward. * */ @Test public void testFocusTransferForwardStopEditingFalse() { JXTable table = new JXTable(10, 2); DefaultCellEditor editor = new DefaultCellEditor(new JTextField()){ @Override public boolean stopCellEditing() { return false; } }; // need to replace generic editor - which fires twice table.setDefaultEditor(Object.class, editor); table.editCellAt(0, 0); // sanity assertTrue(table.isEditing()); CellEditorReport report = new CellEditorReport(); table.getCellEditor().addCellEditorListener(report); table.transferFocus(); assertTrue("table must be editing", table.isEditing()); assertEquals("", 0, report.getEventCount()); }
/** * test that transferFocus methods try to stop edit. * * Here: edit stopped and editor fires on backward. * */ @Test public void testFocusTransferBackwardStopEditing() { JXTable table = new JXTable(10, 2); // need to replace generic editor - which fires twice table.setDefaultEditor(Object.class, new DefaultCellEditor(new JTextField())); table.editCellAt(0, 0); // sanity assertTrue(table.isEditing()); CellEditorReport report = new CellEditorReport(); table.getCellEditor().addCellEditorListener(report); table.transferFocusBackward(); assertFalse("table must not be editing", table.isEditing()); assertEquals("", 1, report.getEventCount()); assertEquals("", 1, report.getStoppedEventCount()); }