public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Execution execution = (Execution) ((ExecutionTableModel) dataModel).getExecution(row); DefaultTableCellRenderer r = (DefaultTableCellRenderer) renderer; r.setForeground(Color.black); if ((row % 2) == 0) r.setBackground(Color.white); else r.setBackground(Color.lightGray); return super.prepareRenderer(renderer, row, column); }
/** * Overridden for performance reasons. See the <a href="#override">Implementation Note</a> for * more information. */ @Override protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { // Strings get interned... if (propertyName.equals("text")) { super.firePropertyChange(propertyName, oldValue, newValue); } }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setText(null); setIcon(((Boolean) value).booleanValue() ? trueIcon : falseIcon); return this; }
/** Returns the cell renderer component. */ public Component getTableCellRendererComponent( JTable table, Object value, boolean selected, boolean focused, int row, int column) { setForeground(null); setBackground(null); setRenderer(row, column); super.getTableCellRendererComponent(table, value, selected, focused, row, column); return this; }
public void paint(Graphics g) { Dimension size = getSize(); int index = 0; if (column == viewIndexForColumn(header.getDraggedColumn())) { index = 2; } else if (isSelected || hasFocus || hasRollover) { index = 1; } skin.paintSkin(g, 0, 0, size.width - 1, size.height - 1, index); super.paint(g); }
@Override public TableCellRenderer getCellRenderer(int row, int column) { MyTableModel model = (MyTableModel) getModel(); if (column == 0) { // JXTable default renderer doesn't align right DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText(model.getToolTipText(row)); renderer.setHorizontalAlignment(JLabel.RIGHT); if (model.isExpert(row, column)) { renderer.setForeground(Color.GRAY); } return renderer; } // code repetition with getCellEditor because of TableCell{Renderer, Editor} // non-inheritance Class<?> klass = model.getClassAt(row, column); PropertyEditorTableAdapter javaBeansRenderer = PropertyEditorTableAdapter.forClass(klass); if (javaBeansRenderer != null) { return javaBeansRenderer; } return getDefaultRenderer(klass); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); String str = Objects.toString(value, ""); if (highlighter.isHighlightableCell(row, column)) { setText("<html><u>" + str); setForeground(isSelected ? table.getSelectionForeground() : HIGHLIGHT); setBackground(isSelected ? table.getSelectionBackground().darker() : table.getBackground()); } else { setText(str); setForeground(isSelected ? table.getSelectionForeground() : table.getForeground()); setBackground(isSelected ? table.getSelectionBackground() : table.getBackground()); } return this; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean selected, boolean focused, int row, int column) { super.getTableCellRendererComponent(table, value, selected, focused, row, column); if (column == 0 || column == 6) { // Week-end setBackground(new Color(255, 220, 220)); } else { // Week setBackground(new Color(255, 255, 255)); } if (value != null) { if (Integer.parseInt(value.toString()) == rday && currentMonth == rmonth && currentYear == ryear) { // Today setBackground(new Color(220, 220, 255)); } } setBorder(null); setForeground(Color.black); return this; }
public Component getTableCellRendererComponent( JTable table, Object value, boolean selected, boolean focused, int row, int column) { setEnabled(table == null || table.isEnabled()); if (column == 0 || column == 1) { setHorizontalAlignment(SwingConstants.CENTER); setForeground(null); setBackground(null); } else { setHorizontalAlignment(SwingConstants.RIGHT); for (int i = 0; i < highlightIndex.size(); i++) { if (row == ((Integer) highlightIndex.elementAt(i)).intValue()) { setForeground(Color.blue); break; } else setForeground(null); } if (row == flashIndex) { setBackground(Color.orange); } else setBackground(null); } super.getTableCellRendererComponent(table, value, selected, focused, row, column); return this; }
/** * Renders a table cell in the main JTable. As a TableCellRenderer, we have to implement this * method, but we use it to colour different types of matches in different ways. Remember that * this is run every time a cell is displayed on the screen, so it needs to be as fast as can be. * * @param table The table which needs rendering. * @param value The object which needs rendering. For now, this can only be a Name object, but * later on we might colour different types of cells in different ways. * @param isSelected Is this cell selected, i.e. is the row selected? * @param hasFocus Is this cell focused, i.e. is this individual cell selected? * @param row The row coordinate of this cell. * @param column The column coordinate of this cell. * @return A component representing this cell. */ @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // TODO: Check if we can get a saving out of this by just rendering a JLabel/JTextField // directly. Component c = defTableCellRenderer.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); // Set all backgrounds to white. c.setBackground(Color.WHITE); if (value == null) { // Null values look null-ish. c.setBackground(COLOR_NULL); return c; } else if (hasFocus) { // ANY cell with focus should look focussed. c.setBackground(COLOR_FOCUS); return c; } else if (Name.class.isAssignableFrom(value.getClass())) { // Aha, a Name! Color it special. Name name = (Name) value; int str_length = name.toString().length(); if (currentMatch == null) { // No current match? Then just colour blank cells blank, // and unmatched name colours special so people know that // they have been recognized as names. if (str_length == 0) { c.setBackground(COLOR_BLANK_CELL); } else { c.setBackground(COLOR_NAME_UNMATCHED); } } else { // So which RowIndex is the match against? RowIndex against = currentMatch.getAgainst(); // System.err.println("Checking against: " + against); if (str_length == 0) { // Mark blank cells as such. c.setBackground(COLOR_BLANK_CELL); } else if (against.hasName(name)) { // Perfect match! c.setBackground(COLOR_NAME_FULL_MATCH); } else if (against.hasName(name.getGenus())) { // Genus-match. c.setBackground(COLOR_NAME_GENUS_MATCH); } else { // No match! c.setBackground(COLOR_NAME_NO_MATCH); } } } else { // Not a name? Note that Strings will NOT make it here: we don't // push Strings through this. So this is really just for later. c.setBackground(COLOR_NULL); } // If the row is selected, make it darker. if (isSelected) c.setBackground(c.getBackground().darker()); return c; }
public JunctionLinkDataFrame(final JunctionLink jl) { super( jl.getCurrName() + " properties", false, // resizable false, // closable false, // maximizable true); // iconifiable // PSRender.onHold(); super.setBackground(back_color); super.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameActivated(InternalFrameEvent e) { reload(); SelectedObject.setSelectedObject(jl); } }); PSRender.moveToTop(jl.getBound(), 0.5); ml = jl; setLocation(50, 50); dataModelMain = new HeadTable(jl); tableMain = new JTable(dataModelMain); tableMain.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); tableMain.setPreferredScrollableViewportSize(new Dimension(500, 20)); // tableMain.setBackground(back_color); // code TableColumn column_code = tableMain.getColumn("Code"); DefaultTableCellRenderer rendererCode = new DefaultTableCellRenderer(); rendererCode.setToolTipText("Enter new code for this path"); column_code.setCellRenderer(rendererCode); column_code.setCellEditor(new TextFieldEditor()); // name TableColumn column_name = tableMain.getColumn("Name"); LanguageButtonRender render_name = new LanguageButtonRender(); render_name.setToolTipText("Path name. Press for change name"); column_name.setCellRenderer(render_name); LanguageButtonEditor editor_name = new LanguageButtonEditor(new JCheckBox()); column_name.setCellEditor(editor_name); // junction 1 TableColumn column_junc_1 = tableMain.getColumn("Junction 1"); MLButtonRenderer rendererJunc_1 = new MLButtonRenderer(); rendererJunc_1.setToolTipText("Code of first Junction, click for open properties"); column_junc_1.setCellRenderer(rendererJunc_1); MLButtonEditor editorJunc = new MLButtonEditor(new JCheckBox()); column_junc_1.setCellEditor(editorJunc); // junction 2 TableColumn column_junc_2 = tableMain.getColumn("Junction 2"); MLButtonRenderer rendererJunc_2 = new MLButtonRenderer(); rendererJunc_2.setToolTipText("Code of second Junction, click for open properties"); column_junc_2.setCellRenderer(rendererJunc_2); column_junc_2.setCellEditor(editorJunc); // type JComboBox comboBoxType = new JComboBox(); String roadNames[] = jl.getTypeNames(); for (int i = 0, len = roadNames.length; i < len; i++) { comboBoxType.addItem(roadNames[i]); } TableColumn column_type = tableMain.getColumn("Type"); DefaultTableCellRenderer rendererType = new DefaultTableCellRenderer(); rendererType.setToolTipText("To change road type click for combo box"); column_type.setCellRenderer(rendererType); column_type.setCellEditor(new DefaultCellEditor(comboBoxType)); // legth TableColumn column_length = tableMain.getColumn("Length"); DefaultTableCellRenderer rendererLen = new DefaultTableCellRenderer(); rendererLen.setToolTipText("The path length in meters"); column_length.setCellRenderer(rendererLen); scrollpaneMain = new JScrollPane(tableMain); scrollpaneMain.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollpaneMain.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); scrollpaneMain.setPreferredSize(new Dimension(500, 50)); Container contentPane = super.getContentPane(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); contentPane.setLayout(gridbag); c.ipady = 0; // make this component tall c.weightx = 0.5; c.gridwidth = 4; c.gridx = 0; c.gridy = 0; gridbag.setConstraints(scrollpaneMain, c); // scrollpaneMain.setBackground(back_color); // scrollpaneMain.setForeground(back_color); contentPane.add(scrollpaneMain); TableModel dataModelPoints = new PointTableModel(jl); tablePoints = new JTable(dataModelPoints); tablePoints.setPreferredScrollableViewportSize( new Dimension(200, dataModelPoints.getRowCount() * tablePoints.getRowHeight())); ListModel lm = new AbstractListModel() { public int getSize() { return 1000; } public Object getElementAt(int index) { return "" + index; } }; JList rowHeader = new JList(lm); rowHeader.setFixedCellWidth(20); rowHeader.setFixedCellHeight(tablePoints.getRowHeight()); // + tablePoints.getRowMargin()); rowHeader.setCellRenderer(new RowHeaderRenderer(tablePoints)); scrollPanePoints = new JScrollPane(tablePoints); scrollPanePoints.setWheelScrollingEnabled(true); scrollPanePoints.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPanePoints.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); int mh; if (dataModelPoints.getRowCount() * tablePoints.getRowHeight() > 100) { mh = 100; } else { mh = dataModelPoints.getRowCount() * tablePoints.getRowHeight(); } scrollPanePoints.setPreferredSize(new Dimension(200, mh)); scrollPanePoints.setRowHeaderView(rowHeader); c.ipadx = 200; c.weightx = 0.5; c.gridwidth = 3; c.gridx = 1; c.gridy = 1; gridbag.setConstraints(scrollPanePoints, c); // scrollPanePoints.setBackground(back_color); contentPane.add(scrollPanePoints); button_ok = new JButton("Ok"); button_ok.addActionListener(this); JPanel buttonPane = new JPanel(null); buttonPane.setPreferredSize(new Dimension(500, 100)); button_ok.setBounds(205, 40, 90, 40); buttonPane.add(button_ok); c.ipady = 10; // make this component tall c.ipadx = 10; c.weightx = 0.5; c.gridwidth = 4; c.gridx = 2; c.gridy = 2; gridbag.setConstraints(buttonPane, c); buttonPane.setBackground(back_color); contentPane.add(buttonPane); super.pack(); super.setVisible(true); // MapApplication.getDesktop().setSelectedFrame(this); }