0

I'm trying to build a custom UI to practice my interface development.

What I would like to do is create a 'sidebar' on a JFrame, which acts as a tabbed pane for a number of JPanels that I would like to be able to switch between.

Currently, I have a 'sidebar' consisting of a number of buttons, and through clicking a button - I would 'hide' one panel, and 'swap in' another (although I am yet unsure of how best to do this). The panels I am creating are the same size, but I do not know how to swap a panel in one position on my UI with another panel, in that same position.

As a result of this I have researched tabbed panes, and these seem like they could be perfect for what I'm trying to implement. I know I can set each pane to display my own JPanel, but I would like the actual tabs to be represented by the custom buttons I have made.

Is this possible with the JTabbedPane class? Or should I continue figuring out how to swap in and out my panels using the button action listener?

Charlie
  • 2,876
  • 19
  • 26
  • Have you looked at [`JTabbedPanesetTabLayoutPolicy`](https://docs.oracle.com/javase/8/docs/api/javax/swing/JTabbedPane.html#setTabLayoutPolicy-int-) and [How to Use Tabbed Panes](https://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html)? Have you considered not using a `JTabbedPane` and instead use a [CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html)? – MadProgrammer Feb 25 '16 at 21:30
  • Possible duplicate of [*Java—Right Clicking JTabbledPane Tab*](http://stackoverflow.com/q/9220889/230513), which cites an example of a custom tab component. – trashgod Feb 25 '16 at 22:08
  • Thanks for the quick response, I believe a CardLayout is exactly what I'm after. – Charlie Feb 25 '16 at 22:54

0 Answers0