Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default color of JTable row

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.

like image 926
Addict Avatar asked Dec 07 '12 21:12

Addict


People also ask

How do I know if a JTable row is selected?

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..

What is JTable How is JTable created?

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.

What is JTable TableModel?

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);

How can you change the appearance of data in cells in JTable?

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.


1 Answers

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

like image 186
Radu Ciopraga Avatar answered Sep 30 '22 13:09

Radu Ciopraga