• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable in JScrollPane sizeing

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi


I want to place JTable in scrollPane to JPanel with BorderLayout.CENTER. What happens is, that the table in my panel component uses only some 50% of the space and is located on the center. What I would like, is that it would use 100% of the size. Another thing is, that I start my app in maximized window, when I minimize it, I would like that scrollPane would take over and make scrollers and not end up "out of frame bounds" of the frame.

I have tried several ways and read lot of "JTable JScrolPane" topics here, but I have not found the answer.

Here is the code to set up the panel:


And later the JPanel gets added to another JPanel into BorderLayout.CENTER.

Help is very welcome.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this JPanel has a BorderLayout as well?

If you haven't specified it explicitly, the JPanel will still have a FlowLayout.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
And this JPanel has a BorderLayout as well?

If you haven't specified it explicitly, the JPanel will still have a FlowLayout.


Yes .. that panel has BorderLayout also set.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setLayout(null);

Then you have no LayoutManager. You can put anything anywhere with any size. Use setBounds()
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK solved my "problem". Yep it was wrong for me to use border layout. I replaced it for GridLayout and it works.
The JPanel constructor is like that:

 
Brian Cole
Author
Ranch Hand
Posts: 903
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Juhan Voolaid:
OK solved my "problem". Yep it was wrong for me to use border layout. I replaced it for GridLayout and it works.
The JPanel constructor is like that:



If super(new GridLayout(1,0)) worked then super(new BorderLayout()) should also have worked.

Could you have been using FlowLayout when you thought you were using BorderLayout as Mr. Prime suggested?

[edit: I wanted to mention that I recommend against using null layout as Ms. Zhang suggests.]
[ September 26, 2007: Message edited by: Brian Cole ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic