Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 05-16-2005, 01:23 AM   #1 (permalink)
Albeeezz
Registered User
 
Join Date: May 2005
Posts: 5
Albeeezz is on a distinguished road
squeeze JPanel horizontally to fit JScrollPane

Hello, I am a beginner using Java and I have some questions in regard to JScrollPane.


I have a JPanel which contains many JTextField's in a single row.

I have placed the JPanel inside a JScrollPane.

I have disabled horizontal scrolling and set vertical scrolling "as needed."

How can I force the JPanel to resize its width to never exceed the width of the JScrollpane to eliminate the need for horizontal scrolling ?

I only want it to exceed vertically if needed so the user may scroll down.

I have tried the JPanel.setSize(); method but it has no effect.


Any help will be greatly appreciated, thank you
Albeeezz is offline   Reply With Quote
Old 05-16-2005, 02:21 AM   #2 (permalink)
Albeeezz
Registered User
 
Join Date: May 2005
Posts: 5
Albeeezz is on a distinguished road
For example,

when you add a JPanel with plenty of JLabel's and JTextField's in a single row to a JFrame, the JPanel will automatically resize its width to fit in the JFrame and make the JLabels and JTextField's shorter.

When you add a JPanel like this to a JScrollPane, it does not resize itself at all and requires you to scroll horizontally.

I have tried the JPanel.setSize() method to manually set the width but to no effect.

I have tried the JScrollPane.setHorizontalScrollBarPolicy(); method
and set it to:
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER,

thinking that the JPanel will automatically resize its width but also to no effect.

I would only like the JPanel to exceed the JScrollPane vertically and sqeeze its width to fit horizontally so i dont need a horizontal scrollbar, only a vertical.

Is there anyone here that can please help me?
Albeeezz is offline   Reply With Quote
Old 05-16-2005, 07:34 AM   #3 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
I don't do much work with GUI's, so I'm not really familiar with Swing, but see if this helps you out at all.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 05-17-2005, 01:01 AM   #4 (permalink)
Albeeezz
Registered User
 
Join Date: May 2005
Posts: 5
Albeeezz is on a distinguished road
Thanks Belisarius, that link really helped alot.
I've now got it working with the

JPanel.setPreferredSize() and the JPanel.setMaximumSize() method

much thanks!
Albeeezz is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 01:06 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting