public TableCellRenderFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); TableModel model = new PlanetTableModel(); JTable table = new JTable(model); table.setRowSelectionAllowed(false); // set up renderers and editors table.setDefaultRenderer(Color.class, new ColorTableCellRenderer()); table.setDefaultEditor(Color.class, new ColorTableCellEditor()); JComboBox<Integer> moonCombo = new JComboBox<>(); for (int i = 0; i <= 20; i++) moonCombo.addItem(i); TableColumnModel columnModel = table.getColumnModel(); TableColumn moonColumn = columnModel.getColumn(PlanetTableModel.MOONS_COLUMN); moonColumn.setCellEditor(new DefaultCellEditor(moonCombo)); moonColumn.setHeaderRenderer(table.getDefaultRenderer(ImageIcon.class)); moonColumn.setHeaderValue(new ImageIcon(getClass().getResource("Moons.gif"))); // show table table.setRowHeight(100); add(new JScrollPane(table), BorderLayout.CENTER); }
/** * Set the current open DarwinCSV. You should really, really, really setCurrentCSV(null) before * you load a new DarwinCSV. * * @param csv The new DarwinCSV object. */ private void setCurrentCSV(DarwinCSV csv) { // Clear the old currentCSV object and matchAgainst object. currentCSV = null; matchAgainst(null); // Load the new currentCSV object. currentCSV = csv; table.removeAll(); table.setDefaultRenderer(Name.class, this); // Set the currentCSV // TODO: This causes an exception occasionally, because we shouldn't // be calling setModel outside of the Event Queue thread; however, we're // currently in a worker thread, so dipping back into the Event thread // would just cause more problems. Sorry! if (csv != null) { table.setModel(currentCSV.getRowIndex()); } else { table.setModel(blankDataModel); } columnInfoPanel.loadedFileChanged(csv); columnInfoPanel.columnChanged(-1); table.repaint(); }
public static void refreshCalendar(int month, int year) { // instantiation String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; int numoday, startom; // Number Of Days, Start Of Month // Allow/disallow buttons prev.setEnabled(true); next.setEnabled(true); if (month == 0 && year <= ryear) { prev.setEnabled(false); } // Cannot set an appointment back in time if (month == 11 && year >= ryear + 50) { next.setEnabled(false); } // Too early to set an appointment lmonth.setText(months[month]); // Refresh the month label (at the top) lmonth.setBounds( 160 - lmonth.getPreferredSize().width / 2, 25, 180, 25); // Re-align label with calendar cyear.setSelectedItem(String.valueOf(year)); // Select the correct year in the combo box // deletes current table for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { mcal.setValueAt(null, i, j); } } // Get first day of month and number of days GregorianCalendar cal = new GregorianCalendar(year, month, 1); numoday = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); startom = cal.get(GregorianCalendar.DAY_OF_WEEK); // Create calendar for (int i = 1; i <= numoday; i++) { int row = new Integer((i + startom - 2) / 7); int column = (i + startom - 2) % 7; mcal.setValueAt(i, row, column); } // Apply renderers Cal.setDefaultRenderer(Cal.getColumnClass(0), new tblCalendarRenderer()); }
// Initializing this component. private void jbInit() { callStackTable.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) { callStackTable_focusGained(e); } public void focusLost(FocusEvent e) { callStackTable_focusLost(e); } }); callStackTable.setTableHeader(null); callStackTable.setDefaultRenderer(callStackTable.getColumnClass(0), getCellRenderer()); scrollPane = new JScrollPane(callStackTable); setVisibleRows(DEFAULT_VISIBLE_ROWS); scrollPane.setLocation(0, 27); setBorder(BorderFactory.createEtchedBorder()); // this.setLayout(null); this.setLayout(new GridBagLayout()); nameLbl.setText("Call Stack"); nameLbl.setBounds(new Rectangle(3, 4, 70, 23)); nameLbl.setFont(Utilities.labelsFont); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = 7; c.gridheight = 1; c.anchor = GridBagConstraints.PAGE_END; c.gridx = 0; c.gridy = 2; this.add(scrollPane, c); c.fill = GridBagConstraints.HORIZONTAL; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 0.0; c.gridwidth = 3; c.gridheight = 1; c.anchor = GridBagConstraints.FIRST_LINE_START; c.gridx = 0; c.gridy = 0; c.insets = new Insets(5, 0, 0, 0); this.add(nameLbl, c); }
/** Constructs a new MemorySegmentComponent. */ public MemorySegmentComponent() { dataFormat = Format.DEC_FORMAT; listeners = new Vector(); errorEventListeners = new Vector(); highlightIndex = new Vector(); segmentTable = new JTable(getTableModel()); segmentTable.setDefaultRenderer(segmentTable.getColumnClass(0), getCellRenderer()); startEnabling = -1; endEnabling = -1; JTextField tf = new JTextField(); tf.setFont(Utilities.bigBoldValueFont); tf.setBorder(null); DefaultCellEditor editor = new DefaultCellEditor(tf); segmentTable.getColumnModel().getColumn(getColumnValue()).setCellEditor(editor); jbInit(); }
/** Create a new, empty property sheet. */ public PropertySheet() { super(new EnhancedTable()); this.getPreferredSize(); props = new ForClassPropertyList(); // Add bean change event listener props.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { // XXX Should I fire a 'stop editing' event here? refresh(); } }); // Add table JTable table = getTable(); MyTableModel tableModel = new MyTableModel(); table.setModel(tableModel); table.setDefaultRenderer(InstancePropertyDescriptor.class, new MyCellRenderer()); table.setDefaultEditor(InstancePropertyDescriptor.class, new MyCellEditor()); }
public NetworkTable(Properties display) { this.display = display; model = new GenericTableModel( new String[] {" ", "Address", "Label", "Description", "Pivot"}, "Address", 256); table = new ATable(model); TableRowSorter sorter = new TableRowSorter(model); sorter.toggleSortOrder(1); Comparator hostCompare = new Comparator() { public int compare(Object a, Object b) { long aa = Route.ipToLong(a + ""); long bb = Route.ipToLong(b + ""); if (aa > bb) { return 1; } else if (aa < bb) { return -1; } else { return 0; } } public boolean equals(Object a, Object b) { return (a + "").equals(b + ""); } }; sorter.setComparator(1, hostCompare); sorter.setComparator(4, hostCompare); table.setRowSorter(sorter); table.setColumnSelectionAllowed(false); table.getColumn("Address").setPreferredWidth(125); table.getColumn("Label").setPreferredWidth(125); table.getColumn("Pivot").setPreferredWidth(125); table.getColumn(" ").setPreferredWidth(32); table.getColumn(" ").setMaxWidth(32); table.getColumn("Description").setPreferredWidth(500); final TableCellRenderer parent = table.getDefaultRenderer(Object.class); table.setDefaultRenderer( Object.class, new TableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { JLabel component = (JLabel) parent.getTableCellRendererComponent(table, value, isSelected, false, row, col); if (col == 4 && Boolean.TRUE.equals(model.getValueAt(table, row, "Active"))) { component.setFont(component.getFont().deriveFont(Font.BOLD)); } else if (col == 1 && !"".equals(model.getValueAt(table, row, "Description"))) { component.setFont(component.getFont().deriveFont(Font.BOLD)); } else { component.setFont(component.getFont().deriveFont(Font.PLAIN)); } String tip = model.getValueAt(table, row, "Tooltip") + ""; if (tip.length() > 0) { component.setToolTipText(tip); } return component; } }); table .getColumn(" ") .setCellRenderer( new TableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { JLabel component = (JLabel) parent.getTableCellRendererComponent( table, value, isSelected, false, row, col); component.setIcon(new ImageIcon((Image) model.getValueAt(table, row, "Image"))); component.setText(""); String tip = model.getValueAt(table, row, "Tooltip") + ""; if (tip.length() > 0) { component.setToolTipText(tip); } return component; } }); table.addMouseListener( new MouseAdapter() { public void all(MouseEvent ev) { if (ev.isPopupTrigger()) { popup.showGraphPopup(getSelectedHosts(), ev); ev.consume(); } } public void mouseClicked(MouseEvent ev) { all(ev); } public void mousePressed(MouseEvent ev) { all(ev); } public void mouseReleased(MouseEvent ev) { all(ev); } }); setLayout(new BorderLayout()); scroller = new JScrollPane(table); add(scroller, BorderLayout.CENTER); }