I’m fairly new to java and am creating a windowbuilder program. I am wondering if it is possible when using Jtabbedpane and switching between the tabs in the program window if i can use an actionlistener to get the contents from a separate class. For example, i have a program with two tabs and two classes, the first tab will have the code from one class and the second tab from the second class.
Thanks
If you want to separate your code which creates GUI, to multiple classes, you could use this aproach:
This would be your main class which will contain
JTabbedPane:This would be your second class which extends
JPanelor some other type of container:Example of third class which also extends
JPanel:Screenshot:
EDIT:
Also, instead of extending classes with
JPanel, it would be wise to create just a method in that class which returns customizedJPanel. This way your class stays “opened” for inheritance.