[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sizing of a JTable using GridBagLayout

Posted on 2006-03-28
5
Medium Priority
?
1,236 Views
Last Modified: 2012-08-13

Hi,

I am displaying a JTable on the screen, but I cannot set the Default width or Height of the table.
No matter what I try, the JTable appears with the same height and width.
The Horizontal scrollbar appears and I can scroll across to see all the columns.

I want the table to appear at a fixed width - say 800 pixels wide. And the horizontal scrollbar only to appear if needed.

JTable table = new JTable(data, columnHeaders);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
container.add(new JScrollPane(table));


I am not sure if the Layout manager i am using is messing with this - prob not.

Can anyone tell me how to fix this please.
Sham
0
Comment
Question by:ShamD
  • 3
  • 2
5 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 16318922
>> container.add(new JScrollPane(table));

The size of the table will be controlled by the size of the scroll-pane.
0
 

Author Comment

by:ShamD
ID: 16319834
Does that mean that if I set the size of the JScrollPane,
The table width should appear wider?

For example;
            JScrollPane f = new JScrollPane(table);
            f.setMinimumSize(new Dimension(500, 500));

0
 
LVL 30

Accepted Solution

by:
Mayank S earned 375 total points
ID: 16319861
Maybe yes - not sure as I have not tried it on GridBagLayout. Try removing any settings for the table width, height and just set it for the scroll-pane - see if that helps.
0
 

Author Comment

by:ShamD
ID: 16321535
Thanks
That worked.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16321627
Any reason for a B-grade?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question