tablecellrenderer

Coloring particular rows according to the first column values in JTable?

安稳与你 提交于 2019-11-27 08:13:34
问题 I'm trying to color particular rows according to the first column values in JTable , but the code below colors the rows according to the row's index. My table has simply four columns. The first column has ID numbers. I need to color the rows according to these ID numbers. For example, if the first ID is 0 and the second is also 0, both of them should be "lightGray". Any idea, please? table_1 = new JTable(){ public Component prepareRenderer(TableCellRenderer renderer,int Index_row, int Index

Swing JTable - Highlight selected cell in a different color from rest of the selected row?

久未见 提交于 2019-11-27 06:12:04
问题 I have a basic swing JTable and the requirement is that when clicked on any cell, the entire row should be highlighted, and also that the cell which was clicked should be a different color from the rest of the highlighted row. Currently, I have isRowSelectionAllowed as true I tried using a custom TableCellRenderer which is as follows: public class CustomTableCellRenderer extends DefaultTableCellRenderer { public static final DefaultTableCellRenderer DEFAULT_RENDERER = new

How to use Renderer for TableHeader

青春壹個敷衍的年華 提交于 2019-11-27 03:54:13
问题 Even I read and test answers by @kleopatra How do I correctly use customer renderers to paint specific cells in a JTable? particular one table header color java swing about super.getTableCellRendererComponent(...) must be last code line before returns, I'm not able to write correct Renderer by those suggestion, for me works only this way JLabel is added for Borders, HorizontalAlignment and Foreground, especially Background caused me a few non_senses by using Component instead of JLabel , (not

Idiomatic table cell renderers in Scala

前提是你 提交于 2019-11-27 02:49:18
问题 I had been using the traditional Java TableCellRenderer approach for providing the renderers in a scala.swing.Table where I declare my renderers on the table's TableColumnModel . The code for this looked like: val myTable = new Table { lazy val tcm = initColumnModel peer.setColumnModel(tcm) override protected def rendererComponent(sel: Boolean, foc: Boolean, row: Int, col: Int) = { //GET THE VALUE FROM THE TableModel val value = model.getValueAt( peer.convertRowIndexToModel(row), peer

How to merge cell in DefaultTableModel/JTable?

帅比萌擦擦* 提交于 2019-11-27 01:29:28
I searched a lot and got some answers for this Q. but many of them referred to links which give 404 error. I want to make table like this: Is there any method in java for this? MultiSpanCellTableExample demonstrates how to merge cells by creating a custom TableUI . There seem to be a problem in this example that causes StackOverflowError , at least in Java 6. To fix this, inside AttributiveCellTableModel.setDataVector() replace: setColumnIdentifiers(columnNames); with: this.columnIdentifiers = columnNames; IE: public void setDataVector(Vector newData, Vector columnNames) { if (newData == null)

how to add different JComboBox items in a Column of a JTable in Swing

前提是你 提交于 2019-11-26 22:59:44
I want to add JComboBox inside a JTable (3,3) on column 1. But in the column 1 , each row will have its own set of ComboBox element. When I tried to use table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox_Custom)); Each row is being set to same set of ComboBox Values. But I want each row ComboBox has different items. example on java2s.com looks like as works and correctly, then for example (I harcoded JComboBoxes for quick example, and add/change for todays Swing) import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.UIManager

TableCellRenderer and how to refresh Cell background without using JTable.repaint()

陌路散爱 提交于 2019-11-26 17:55:46
is possible to refresh background based on value from outside correctly, without to force for repaint table.repaint(); Based, used and tested with great code made by kleopatra and Hovercraft Full Of Eels valid for Java6/7, because there weren't any changes in APIs my SSCCE works correctly, repainted by JTable.repaint() import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax

Change background color of JTable row based on column value

柔情痞子 提交于 2019-11-26 17:17:22
问题 hi i am new in java jtable cellrendered. I am looking for a way that works in my program but i dont have any luck finding it. Here is my Jtable Employee ID | Name | Status | Position 00565651 Roger Active Manager 00565652 Gina Active Crew 00565652 Alex Inactive Crew 00565652 Seph Active Manager the data came from ms access database but i want to change the background/foreground of the rows which has a value of "inactive" in status column. I found many examples in the internet but all of it is

Change the background color of a row in a JTable

心不动则不痛 提交于 2019-11-26 16:41:17
问题 I have a JTable with 3 columns. I've set the TableCellRenderer for all the 3 columns like this (maybe not very effective?). for (int i = 0; i < 3; i++) { myJTable.getColumnModel().getColumn(i).setCellRenderer(renderer); } The getTableCellRendererComponent() returns a Component with a random background color for each row. How could I change the background to an other random color while the program is running? 回答1: One way would be store the current colour for each row within the model. Here's

How to make a JButton in a JTable cell click-able?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 14:42:11
I have a JTable with a custom cell renderer. The cell is a JPanel that contains a JTextField and a JButton. The JTextField contains an integer, and when the user clicks on the JButton the integer should be increased. The problem is that the JButton can't be clicked when I have it in a JTable cell. How can I make it click-able? Here is my test code: public class ActiveTable extends JFrame { public ActiveTable() { RecordModel model = new RecordModel(); model.addRecord(new Record()); JTable table = new JTable(model); EditorAndRenderer editorAndRenderer = new EditorAndRenderer(); table