Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:41:15+00:00 2026-06-08T12:41:15+00:00

I have added a table, but the problem is, the panel doesnt show its

  • 0

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.

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

Output

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:41:17+00:00Added an answer on June 8, 2026 at 12:41 pm

    Scroll Panes contain another component, known as the ViewPort. This is actually where the components been assigned to the scroll pane get added.

    If you want to maintain the JTable as transparent (table1.setOpaque(false);), then you need to change the view ports background

    scroll1.getViewport().setBackground(ivory);
    

    Otherwise, set the table to opaque and table1.setFillsViewportHeight(true); to force the table to fill the entire viewport

    UPDATED

    Works fine for me

    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");
    
    for (int index = 0; index < 10; index++) {
    
        Vector vector = new Vector();
        vector.add("p" + index);
        vector.add("n" + index);
        vector.add("c" + index);
        vector.add("e" + index);
        vector.add("s" + index);
        vector.add("c" + index);
        vector.add("t" + index);
        vector.add("s" + index);
        vector.add("s" + index);
        vector.add("r" + index);
    
        model1.addRow(vector);
    
    }
    
    table1 = new JTable(model1);
    Color ivory = new Color(255, 255, 208);
    table1.setOpaque(true);
    table1.setFillsViewportHeight(true);
    table1.setBackground(ivory);
    
    JScrollPane scroll1 = new JScrollPane(table1);
    table1.getTableHeader().setBackground(ivory);
    add(scroll1, BorderLayout.CENTER);
    

    You can comment out the row creation section and it will still paint in ivory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table like below and its rows can be added and removed
I am building an app using storyboard. I have added a table view to
I have added checkbox in display table using decorator class as shown in below
Most of my content is in a new table I have added to JOOMLA
I have been able to set up OBDC in Filemaker, and added table ,
I have my table view and the cells within it have the UILongPressGestureRecognizer added
I have a table FOLDERS ,everytime a folder is added through a php page
I have defined a table type PL/SQL variable and added some data there. create
I have a table. Some rows are dynamically added by jquery. The first <td>
I have an update panel which contains a table, to which I add rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.