I have written one program where I am highlighting certain rows based on criteria.I posted one question regarding that :- JTable CustomRenderer Issue
Solution given for this problem was that I need to set color in else for rows which do not come under criteria. So I decided that in else I will use default color of JTable
. Modified code is
else{
c.setForeground(DefaultLookup.getColor(this, ui, "Table.dropCellForeground"));
c.setBackground(DefaultLookup.getColor(this, ui, "Table.dropCellBackground"));
}
So far so good, I am getting required behaviour, but when I am trying to make jar following warning is coming :-
warning: DefaultLookup is internal proprietary API and may be removed in a future release
So can any one suggest me if there is any other way to setting rows to default color in JTable
.
JTable has a getSelectionModel() method which will give you a ListSelectionModel object. It tells you what rows are selected. You can add a ListSelectionListener to that via the addL..S..
The JTable class is a part of Java Swing Package and is generally used to display or edit two-dimensional data that is having both rows and columns. It is similar to a spreadsheet. This arranges data in a tabular form.
The TableModel interface specifies the methods the JTable will use to interrogate a tabular data model. The JTable can be set up to display any data model which implements the TableModel interface with a couple of lines of code: TableModel myData = new MyTableModel(); JTable table = new JTable(myData);
We can change the background and foreground color for each column of a JTable by customizing the DefaultTableCellRenderer class and it has only one method getTableCellRendererComponent() to implement it.
Replacing DefaultLookup.getColor(this, ui, "Table.dropCellForeground")
with
javax.swing.UIManager.getColor("Table.dropCellForeground")
should fix your problem.
Also you can modify (globally) the default values present in your Look & Feel just by using the put(Object key, Object value)
method from UIManager
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With