Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Size of JTable in JScrollPane

Posted on 2001-06-04
4
Medium Priority
?
4,397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Accepted Solution

by:
boazbl1 earned 150 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

704 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