Note that there are some explanatory texts on larger screens.

plurals
  1. POChange background color of JTable
    primarykey
    data
    text
    <p>I have added a table, but the problem is, the panel doesnt show its background color. I have tried setting scrollpane background color, etc. But it doesn't work. The frame has a button 'Verify', which when clicked, displays a table beneath it. Until it is clicked, the portion where the table will appear is solid gray. I want the whole portion to be ivory background. Kindly help me diagnose the problem. </p> <pre><code>try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn1=DriverManager.getConnection("jdbc:odbc:vasantham","",""); Statement st1=conn1.createStatement(); ResultSet rs1=st1.executeQuery("select * from try where DATEDIFF('d',NOW(),exdate) &amp;lt; 61 order by tname"); ResultSetMetaData md1=rs1.getMetaData(); int cols1=md1.getColumnCount(); model1=new DefaultTableModel(); model1.addColumn("Purpose"); model1.addColumn("Name"); model1.addColumn("Composition"); model1.addColumn("Expiry"); model1.addColumn("Stock"); model1.addColumn("Cost"); model1.addColumn("Type"); model1.addColumn("Supplier"); model1.addColumn("Supplier Number"); model1.addColumn("Rack"); table1=new JTable(model1); Color ivory=new Color(255,255,208); table1.setOpaque(false); table1.setBackground(ivory); String[] tabledata1=new String[cols1]; int i=0; while(rs1.next()) { for(i=0;i&amp;lt;cols1;i++) { if(i==3) { Date intr1=(rs1.getDate(i+1)); tabledata1[i]=formatter1.format(intr1); } else tabledata1[i]=rs1.getObject(i+1).toString(); } model1.addRow(tabledata1); } JScrollPane scroll1 = new JScrollPane(table1); scroll1.setBackground(new Color(255,255,208)); scroll1.getViewport().setBackground(ivory); panel1.setLayout(new BorderLayout()); panel1.setBackground(ivory); table1.getTableHeader().setBackground(ivory); panel1.add(scroll1,BorderLayout.CENTER); frame1.add(panel1,BorderLayout.CENTER); conn1.close(); } </code></pre> <p><img src="https://i.stack.imgur.com/6vPPk.jpg" alt="Output"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload