|
-
Nov 6th, 2003, 09:28 AM
#1
Thread Starter
Hyperactive Member
Jtable Cell colour
Hi,
How do I add a certain colour to the background of an individual cell?
Thanks
-
Nov 7th, 2003, 02:15 AM
#2
Dazed Member
To change the color of a selected cell you would want to call either setSelectionForeground(Color selectionForeground) or setSelectionBackground(Color selectionBackground). setGridColor(Color gridColor) is also pretty fun to use.
-
Nov 7th, 2003, 04:07 AM
#3
Thread Starter
Hyperactive Member
thanks, but how do I do this?
-
Nov 8th, 2003, 06:29 PM
#4
Dazed Member
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class G{
public static void main(String[] args){
JFrame jf = new JFrame("Inventory");
Container c = jf.getContentPane();
Object[] colnames = {"Title", "Author", "Isbn", "Price"};
Object[][] data = {
{"Weaveworld", "CliveBarker", "125457", new Double(9.56)},
{"Watership Down", "Richard Adams", "898454", new Double(8.43)},
{"The Guardian", "John Saul", "87987", new Double(10.98)},
};
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
JTable jt = new JTable(data, colnames);
jt.setGridColor(Color.RED);
jt.setSelectionBackground(Color.yellow);
JScrollPane scrollableTable = new JScrollPane(jt);
c.add(scrollableTable);
jf.setSize(500, 100);
jf.setVisible(true);
}
}
-
Nov 11th, 2003, 05:44 AM
#5
Thread Starter
Hyperactive Member
I have tried this, and all this has acheived is setting the whole row to yellow, when a cell in that row is selected.
I want to set a single cell colour to a set colour (ie yellow)
example:
if cell.value = 45 then make that cell yellow
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|