Dynamic resizing of JPanel

L

Lobang Trader

Dear experts,

I have the a JDesktopPane and a JPanel added to the CENTER and SOUTH
position of a JFrame respectively.

I would like to dynamically resize the JPanel upon mouseExited like the
Windows TaskBar.

On mouseExited of the JPanel i set the bounds of the JPanel to a new
size. However, the sizes do not reflect visually. I have called
invalidate(), validate(), repaint() and none seems to work.

Other than using JSplitPane to create a resizable JPanel, how can I make
this work?

Others have suggested using LayoutManagers but which one and how?

Thank you in advance.
 
A

ak

I have the a JDesktopPane and a JPanel added to the CENTER and SOUTH
position of a JFrame respectively.

I would like to dynamically resize the JPanel upon mouseExited like the
Windows TaskBar.

seems that you need JSplitPanel
 
B

Babu Kalakrishnan

Followups set to c.l.j.gui.

Lobang said:
Dear experts,

I have the a JDesktopPane and a JPanel added to the CENTER and SOUTH
position of a JFrame respectively.

I would like to dynamically resize the JPanel upon mouseExited like the
Windows TaskBar.

On mouseExited of the JPanel i set the bounds of the JPanel to a new
size. However, the sizes do not reflect visually. I have called
invalidate(), validate(), repaint() and none seems to work.

Setting the bounds of a panel will not help because the moment it is
revalidated, its size will again be set to the preferred value (only the height
actually since it is the SOUTH component of a BorderLayout) by the
LayoutManager.

Override the getPreferredSize method of the JPanel to return a different
value based on a flag. Set / reset the flag in the mouseExited/Entered events
and revalidate the container.

e.g.

private boolean minimized = false;

public Dimension getPreferredSize()
{
Dimension pref = super.getPreferredSize();
if (minimized) pref.height = 5;
return pref;
}

BK
 

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

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top