PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Any Java experts?

I'm having a bit of trouble with a Swing app I'm building. It consists of a JTabbedPane which contains, in each tab, another JTabbedPane and within each of those tabs, a class which extends JPanel.

What I'd like to do is be able to switch a tab automatically, ie, changing the tab in the outer tabbedpane and then changing to one in the inner tabbed pane.

How would I refer to these outer tabbed panes from within the JPanels? I'm at a bit of a loss - I'm assuming I'd need to mess around with action events, but I have no idea where I'd set them up so they're accessible to the panel classes.

Thanks,

David.
How would I refer to these outer tabbed panes from within the JPanels?
You shouldn't. Talk to an intermediate.

Have a look at the MVC (model, view, controller) design pattern. You probably want to be implementing the panels as the view and then talking to the controller to be changing pages.
Found a quick and dirty fix in the end - I simply passed the parent JTabbedPane to the child in its constructor. Next time I'll do it the proper way. ;)

Thanks Refractor.