Solved

Size of JTable in JScrollPane

Posted on 2001-06-04
4
4,385 Views
Last Modified: 2012-06-27
Hi,
Visualisation of JTable located in JScrollPane is allways same and to big for my needs. I try to chage size using JViewport 's setExtentSize but no use. How should it be done properly? Is this Layout manager issue? Here is the sample how I tried:

JPanel a = new JPanel();

JTable t = new JTable(0,5);
JScrollPane sp = new JScrollPane(t);
sp.getViewport().setExtentSize(new Dimension(100,100));

a.add(sp);
this.add(a);
0
Comment
Question by:mira84
4 Comments
 
LVL 1

Accepted Solution

by:
boazbl1 earned 50 total points
ID: 6151939
the JTable will fill all of the JScrollPane. try to change the size of the JScrollPane using Layout Manager.
0
 
LVL 92

Expert Comment

by:objects
ID: 6154364
I don't think your problem is with the table in the scroll pane, it's more related to the placement of the scroll pane and the layout manager of its parent.
0
 
LVL 1

Expert Comment

by:clim1219
ID: 6154743
Hi mira84,

The problem is in the Layout Manager of JPanel. By default the Layout Manager of JPanel is FlowLayout. In order to have the desire size of the JScrollPane you should use  GridBagLayout in JPanel.

Example:

JPanel pnlTest = new JPanel( new GridBagLayout() ) ;
JTable tblTest = new JTable( 0, 5 ) ;
JScrollPane scrTest = new JScrollPane( tblTest ) ;
pnlTest.add( scrTest, new GridBagConstraints( 0, 0,
    1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
    GridBagConstraints.NONE,
    new Insets( 5, 5, 5, 5 ), 100, 100 ) ) ;

// change the GridBagConstraints to the ideal size you
// want

this.add( pnlTest ) ;

Happy coding,
clim1219
0
 

Expert Comment

by:YamunaiThuraivan
ID: 6170353
Hi,
        use the method in the JTable class
           setPreferredScrollableViewPortSize(new Dimension(width,height));
        I think this will change the size of the JTable.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 53
tomcat administrtor 12 47
hibernate example for saving data 19 38
runtime exception 2 28
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

770 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