Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Set size of JTable inside a JScrollPane

Thread view: 
Allan Valeriano - 15 Jun 2007 17:51 GMT
Hi,

I'm inserting a JTable into a JScrollPane which is inserted inside a
JPanel. I'd like to set the size of this JScrollPane to be the same as
the JPanel, so it will show a blank space between the end of my JTable
and the end of my JScrollPane.
I've tryed something like:

table.setPreferredScrollableViewportSize(panel.getSize());

but is not working as I wanted. On this picture, there is a grey space
between the end of the table and the end of the window:
http://java.sun.com/docs/books/tutorial/figures/uiswing/components/TableRenderDe
mo.png


This is because the JScrollPane resizes itself, to fit the size of the
table, but I want it not to resize like that if the table is smaller
then the Panel, so there will be a blank space between the last table
row and the end of the JScrollPane and not between the end of the
JScrollPane and the end of the window.

Does anybody knows how can I do that?
Andrew Thompson - 16 Jun 2007 06:21 GMT
...
>...show a blank space between the end of my JTable
>and the end of my JScrollPane.
>I've tryed something like:

Please do not wast your time, and our bandwidth,
describing 'something like' the code, input or output.
SSCCE's* and copy/pasted input and output are 1000%
more useful.

* <http://www.physci.org/codes/sscce.html>

>table.setPreferredScrollableViewportSize(panel.getSize());
>
>but is not working as I wanted.

What layouts are you using?  (considers) No, answer
that in your SSCCE.

>..On this picture, there is a grey space
>between the end of the table and the end of the window:
>http://java.sun.com/docs/books/tutorial/figures/uiswing/components/TableRenderDe
mo.png

I see a white space when I run the code in Java 6..
<http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TableRenderD
emoProject/src/components/TableRenderDemo.java


You did try running that code, didn't you?  It seems to
behave exactly as you describe you want it to.  (Except
the color is white).

>This is because the JScrollPane resizes itself, to fit the size of the
>table, but I want it not to resize like that if the table is smaller
[quoted text clipped - 3 lines]
>
>Does anybody knows how can I do that?

Well.. you could use the above linked code, that works,
or change it one line at a time to your needs, and post
the result of the first change that stops acting as you
expect.

(I suspect it is the layouts - or lack of them - that
are used in the code.  But only the code will tell
the tale.)

Signature

Andrew Thompson
http://www.athompson.info/andrew/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.