Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot see two Jtables until resize  RSS feed

 
Haris Tasawar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys,
I am running into a problem and i need help, i basically have a jframe with two JPanels which would hold the JScrollpanes of jtables, there are also two JTextFields who would act as a search bar for populating the the Jtable, the programming of data is done correctly but i am running into a problem, the second Jtable does not show until and unless i resize the jframe window, i cant get it to work. I have tried validate(), update(), setvisible() but it wont work,

Please guys i need your help.

I have add screenshots for reference and the code i given below:


Thanks.



before.PNG
[Thumbnail for before.PNG]
Before Resize
after.PNG
[Thumbnail for after.PNG]
After Resize
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You are making it extremely difficult for us to help you:

1) The code has lot of empty lines. This is a waste of space and makes it difficult for us to read code by going up and down. Whn didn't you remove them when you posted?
2) You should provide a SSCCE for us to help you. You have not done that. You have included JDBC stuff for which we don't have that setup and niether are we interested in setting that up on our machines.
3) The code itself has several problems. Out of the 300 lines, the main() method has 250 lines. This is bad programming. You should have the class extend JPanel or JFrame and add all the GUI stuff in the constructor or a method. The main method should just create the instance or JFrame and show it (and this should be done inside invokeLater).
4) I don't think you have provided us the complete details. Both the tables show up only when the user hits the respective 'search' buttons, isn't it? why haven't you told us about that? You have to tell the details
5) When you add a component at runtime after the frame is visible (which happens when you click the buttons for the first time), you should call revalidate() and repaint() - you have called only repaint().
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Containers with null layout(s) are always bad news.
Recommended reading http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html

For a scrollable table, I would recommend a BorderLayout with the JScrollPane added to the Center
 
Haris Tasawar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am sorry for the bad programming, its just that i didnt had it in mind when i was creating the project, i would surely re implement the code using different classes for sure, from next time i would make sure that i used proper formatting of the post.... Sorry about that, anyways i would do the revalidate and let you guys know
 
Haris Tasawar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and as for the border layout, is is possible to implement two Jtables in the center, maybe it isnt, also i put the Revalidate() method and still i see no table?
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haris Tasawar wrote:and as for the border layout, is is possible to implement two Jtables in the center, maybe it isnt

It definitely isn't. A BorderLayout only supports up to 5 components, one in each region (north, south, west, east, center). To put two components in the center you must nest them in another control; I suggest either a JSplitPane to allow resizing them, or a JPanel with a GridLayout if they need to have the same sizes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!