Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have Collapsable/Expandable JPanel in Java Swing

I want a JPanel that can be Collapsed or Expanded when user clicks on a text/icon on its border. I need this type of panel due to space crunch in my application.

I read about CollapsiblePanel class but not sure how to use it.. I think SwingX is needed to be downloaded but did not find that anywhere.

Moreover, it would be better if I get the solution to this in basic Java Swing.

like image 691
Nayan Soni Avatar asked Nov 18 '11 04:11

Nayan Soni


People also ask

What are the 3 types of Java Swing containers?

As we mentioned before, Swing provides three generally useful top-level container classes: JFrame , JDialog , and JApplet .

How do I make a transparent JPanel?

You can simply create your jPanel using drag and drop, as you always do and then for changing the panel's color and making it transparent or semi-transparent you can use this code: panel. setBackground(new Color(0.0f, 0.0f, 0.0f, 0.5f));

How do I change the layout of a JPanel?

You can set a panel's layout manager using the JPanel constructor. For example: JPanel panel = new JPanel(new BorderLayout()); After a container has been created, you can set its layout manager using the setLayout method.


1 Answers

not sure where you looked, but it's not that difficult to find - even given the infrastructure mess we are in ;-)

Go to the project home of SwingX, then follow the link in the first paragraph to the (barebone) download section, down to releases\1.6.2. Nothing special to the collapsibles themselves, just containers to put components into.

like image 176
kleopatra Avatar answered Oct 04 '22 00:10

kleopatra