Resizing Components of JPanel in Beans

A

asd

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.
 
A

Andrew Thompson

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.

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.
 
A

asd

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


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.

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.
 
I

Ian Wilson

asd said:
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
 
A

asd

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.



Removing the layout manager seems rather foolish to me.



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

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);

}

}
 
A

asd

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.



Removing the layout manager seems rather foolish to me.



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

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);

}

}

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top