dcsimg
JTable display messes up form
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Gustavo_Pinheiro
Posted On:   Sunday, September 28, 2003 07:14 PM

Hi all, I have a rather complex GUI composed of many panels and tables. I use mainly GridBagLayout. The user must be able to add rows to two of those tables by pressing a + button (or remove rows by pressing a - button). As the rows are being added, they get over the other components. I thought the containers had to be informed of the change in table size so my first attempt to solve the problem was to call frame.pack() after I added the new rows and it did not work (the new rows did not showed up). Then I tried to resize the panels programmatically, but the components other than the table did not get rearranged properly or at all and the resized table was on front of them. I was told to call revalidate() or validat   More>>

Hi all,

I have a rather complex GUI composed of many panels and tables. I use mainly GridBagLayout. The user must be able to add rows to two of those tables by pressing a + button (or remove rows by pressing a - button).
As the rows are being added, they get over the other components.
I thought the containers had to be informed of the change in table size so my first attempt to solve the problem was to call frame.pack() after I added the new rows and it did not work (the new rows did not showed up).

Then I tried to resize the panels programmatically, but the components other than the table did not get rearranged properly or at all and the resized table was on front of them.
I was told to call revalidate() or validate() on the panels and the main frame, but it didn't work also.

Bottom line is: after a table changes size, the rest of the GUI should get resized accordingly, but I can't get it to.

Here's the code that adds rows to the table and try to adjust the whole form:

			
// gets the table model
DefaultTableModel dtm = (DefaultTableModel) jTableA.getModel();
// adds the new row (empty)
dtm.setRowCount( jTableA.getRowCount() + 1 );
// resizes the JTable
jTableA.setPreferredSize( new Dimension( jTableA.getWidth(), // width jTableA.getHeight() + 20 ) ); // height
// resizes its scrollpane
jScrollPaneA.setSize( new Dimension( jScrollPaneA.getWidth(), jScrollPaneA.getHeight() + 20 ) );
// resizes the panels containing the table
jPanelInputMatrix.setSize(jPanelInputMatrix.getWidth(), jPanelInputMatrix.getHeight()+20);
jPanelPilha.setSize(jPanelPilha.getWidth(), jPanelPilha.getHeight()+20);
// validates and pack
jPanelInputMatrix.validate();
jPanelPilha.validate();
this.validate();
pack();
   <<Less

Re: JTable display messes up form

Posted By:   Gustavo_Pinheiro  
Posted On:   Sunday, September 28, 2003 07:22 PM

Sorry about the crappy layout. I hitted submit accidentally instead of edit. The contents are alright though.
About | Sitemap | Contact