File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTable in JScrollPane sizeing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable in JScrollPane sizeing" Watch "JTable in JScrollPane sizeing" New topic
Author

JTable in JScrollPane sizeing

Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

And this JPanel has a BorderLayout as well?

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
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

Joined: Nov 14, 2000
Posts: 1953
setLayout(null);

Then you have no LayoutManager. You can put anything anywhere with any size. Use setBounds()
Juhan Voolaid
Ranch Hand

Joined: Nov 18, 2003
Posts: 179
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

Joined: Sep 20, 2005
Posts: 862
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 ]

bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable in JScrollPane sizeing