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 / March 2007

Tip: Looking for answers? Try searching our database.

Resizing Components of JPanel in Beans

Thread view: 
asd - 04 Mar 2007 21:04 GMT
Hello All,

I am developing a bean. I am using JPanel and in that JPanel there is a
list box.

After user drags and drops the bean to BDK everything works perfect. After
the user resizes the bean (JPanel) only the beans gets resized and its
contents still have the same small size.

Is there a way to resize the components of a JPanel when doing beans?

In addition to that, which function of the bean (JPanel) is called when it
is being resized? I tried overriding several functions (setSize,
resize etc) but they are not called when the bean is resized in BDK.
Thank you so much for your help.
Sincerely yours.
Andrew Thompson - 06 Mar 2007 00:42 GMT
> Hello All,
>
[quoted text clipped - 4 lines]
> the user resizes the bean (JPanel) only the beans gets resized and its
> contents still have the same small size.

It sounds as though you may need to become
familiar with layouts, are you familiar with
the term?

> Is there a way to resize the components of a JPanel when doing beans?

Sure, if the code is done right, the user
drags the window bigger/smaller, and the
component automatically adjusts.

There should be no need, generally, for the
developer to set the size of basically anything
beyond custom compontents, and maybe JScrollPane's.

If you need to set a size, it usually indicates
a problem with the layout(s).

Andrew T.
asd - 06 Mar 2007 03:58 GMT
>> Hello All,
>>
[quoted text clipped - 23 lines]
>
> Andrew T.

Hello Andrew,

Thank you so much for your time.
I have a JScrollPane and a JList in a JPanel. Using the default layout
manager nothing happens. The size of the JScrollPane
does not change. Now I removed the layout manager. I manually adjust the
size of the JScrollPane when ever the user clicks on it.

I would be glad if you could mention me how to do it using the layout
manager. An example code will be perfect if you have time and will to
send one.
Thanks again.
Sincerely yours.
Ian Wilson - 06 Mar 2007 09:27 GMT
> I have a JScrollPane and a JList in a JPanel. Using the default layout
> manager nothing happens. The size of the JScrollPane
> does not change.

You must be using the layout manager incorrectly, why not post a small
working Java program that illustrates your problem, then people can
point out how to fix it.

> Now I removed the layout manager. I manually adjust the
> size of the JScrollPane when ever the user clicks on it.

Removing the layout manager seems rather foolish to me.

> I would be glad if you could mention me how to do it using the layout
> manager. An example code will be perfect if you have time and will to
> send one.

I'd use BorderLayout (the default for content panes) and
 add (scroller, BorderLayout.CENTER);
http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html
asd - 07 Mar 2007 01:28 GMT
>> I have a JScrollPane and a JList in a JPanel. Using the default layout
>> manager nothing happens. The size of the JScrollPane
[quoted text clipped - 16 lines]
>   add (scroller, BorderLayout.CENTER);
> http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html

I compiled following code as a Bean. When the size of the panel Changes
the size of the JScrollPane stays the same. I would like size of
ScrollPane to always fit the size of the Panel.
I hope I made myself clear this time.

public class TestFoolness extends JPanel{
   JList lst;
   JScrollPane pn;
   
   /** Creates a new instance of TestFoolness */
   public TestFoolness() {
       super();    // gets default layout manager
       
       lst = new JList(new String[] {"asd", "qvy", "zxc"});
       pn = new JScrollPane(lst);
       
       add(pn);
       
   }
   
}
asd - 07 Mar 2007 04:44 GMT
>>> I have a JScrollPane and a JList in a JPanel. Using the default layout
>>> manager nothing happens. The size of the JScrollPane
[quoted text clipped - 38 lines]
>    
> }

Thank you so much for your help Ian. After trying several different
things. I figured that out it works with BorderLayout. I had been trying
to do it with default LayoutManager.
I really appreciate your help.


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.