2

I currently have a row of JPanels that I add to a JFrame. I need these panels to be able to expand and collapse as to minimize the clutter on the JFrame.

Right now, I just create the JPanels and add them to the JFrame one at the time.

public void addFolderSearch(FolderSearchComp fsc) {
    folderCompPanel.add(fsc, folderCompPanel.getComponentCount());
    remake();
}

I've tried adding these FolderSearchComps (the JPanels) to a TitledPane and then adding the TitledPane to the JFrame, but the titledpane.setContent() wont take the JPanel as a parameter.

Is there any way to add a JPanel to a TitledPane and then adding that TitledPane to the JFrame?

Roberto Anić Banić
  • 1,411
  • 10
  • 21
Jonas Olesen
  • 568
  • 5
  • 25
  • 1
    When you say `TitledPane`, do you mean `javafx.scene.control.TitledPane` ? If that is the case, you are trying to mix Swing and JavaFX code. Adding Swing components to a JavaFX application is possible (see [the tutorial](https://docs.oracle.com/javafx/8/embed_swing/jfxpub-embed_swing.htm)), but perhaps not what you were looking for – Robin May 18 '15 at 12:43
  • yes that is what i mean, is there any swing component similar to the titledpane? or any other workaround to expand and collapse the jpanel – Jonas Olesen May 18 '15 at 12:44
  • 1
    You are looking for an ["accordion"](http://stackoverflow.com/questions/2944256/accordion-for-swing). – Joop Eggen May 18 '15 at 12:51

1 Answers1

1

is there any swing component similar to the titledpane? or any other workaround to expand and collapse the jpanel

There is a complete set of Swing components extension in SwingX library which includes titled pane, task pane and collapsible pane, just to mention the ones that you are looking for.

Take a look to this related Q&A: How to create expandable panels using swing?. You might also want to have a look to the demos: SwingLabs demos

Community
  • 1
  • 1
dic19
  • 17,821
  • 6
  • 40
  • 69