aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem displaying JTable inside a JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem displaying JTable inside a JScrollPane" Watch "Problem displaying JTable inside a JScrollPane" New topic
Author

Problem displaying JTable inside a JScrollPane

Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 226

I have this Frmae that should show tables inside another Panel with GridBagLayout. Part of the code is here. Problem is that the tables show up as white areas with border and they are not populated when a button for the same is pressed (code not included here), though the tablemodels are properly populated (debug statments tell me that). Any flaw with this code?

[ September 22, 2004: Message edited by: Debashish Chakrabarty ]

Debashish
SCJP2, SCWCD 1.4
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Try compiling and running this:
Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 226

Few things I did not mention:
  • I have this in a JInternalFrame (don't think makes a difference)
  • I have two TableModels associated with these tables.
  • The data changes (search logic) and tables need to be repopulated on each button press.
  • There are no tables headers to display (I tried getting rid of scroll pane on this account, but tables still show no data)

  • While I am able to run the above said code as a Frame and some modified code as JInternal Frame and using a TableModel. I am still not able to populate the data in my tables in the project code. The tables need to be populated with data that I feed in the models and call fireTableDataChanged(). The TableChanged event is called religiously after this, my debug statements tell me that Models have the data. But still the Tables would display nothing. The whole Table area is a big White box with border, nothing else.

    Any one who could help me get out of this quagmire?
    [ September 22, 2004: Message edited by: Debashish Chakrabarty ]
    Debashish Chakrabarty
    Ranch Hand

    Joined: May 14, 2002
    Posts: 226

    I guess the reason the table was not displaying was that I was not doing this:

    Now to the new problem: Though I have set the "Preferred sizes" of both tables as same, the code is identical for both the tables, yet the Header table displays in its full glory with width as I defined, but Detail one is shrinked to a few pixels. I could see that data is there in the cells when I click on them (the column shows it as "...").

    Basically, the idea is each column of Header table, the checkbox below and the corresponding column in the detail below should be in one vertical plane or line (seemingly a single table having 12 columns).

    I wonder that when the code is identical for both tables what makes one of the tables to appear shrinked at the center of the Scroll Pane.

    Any help on this would be appreciated. Thanks for your time.
    [ September 22, 2004: Message edited by: Debashish Chakrabarty ]
    Craig Wood
    Ranch Hand

    Joined: Jan 14, 2004
    Posts: 1535
    Components will collapse to 10 x 10 when there isn't enough room for them to be displayed in a GridBagLayout. I would try dragging the top/bottom and sides of the JInternalFrame until the JTable opens up. Another thing to try is to get a readout in the console (System.out.println) of its preferred size after the call to setVisible at the end of the constructor to find out what size it needs for display.
     
     
    subject: Problem displaying JTable inside a JScrollPane