While there are any number of other directions in which we could go next
with GUIs, I am going to spend a webpage on
JTabbedPanels. Having tabbed panes can be very useful in
order to get more in a GUI. As you'd expect, each pane can have its
own layout and tab identifier.
JTabbedPanes are configured to work with ChangeListener in order to respond to user actions.
But first we present the constructor.
|JTabbedPane( )||This constructor is used with no arguments|
|In order to work with tabbed panes there are a significant number of methods that the developer is likely to require at some point in time.|
|insertTab(String title, Icon icon, Component component, String tip, int index)||insert a tab with the specified values at location index|
|addTab(String title, Icon icon, Component component, String tip)||add a tab with the specified characteristics|
|addTab(String title, Icon icon, Component component)||add a tab with the specified characteristics|
|addTab(String title, Component component)||add a tab with the specified characteristics|
|removeTabAt(int Index)||remove a tab at the specified index|
|getSelectedIndex( )||returns the index of the selected tab|
|setSelectedIndex(int Index)||sets the selected tab to the one with the specified index|
|getSelectedComponent( )||returns the selected component|
|getComponentAt(int Index)||returns the component at a particular index|
|setComponentAt(int Index, Component component)||sets the particular component at the specified index|
|indexOfTab(String title)||gets the index of a tab based on the title|
|indexOfComponent(Component compnent)||gets the index of a tab based on the component|
|getTabCount( )||gets the number of tabs|
|Each pane in a GUI can be quite different from another,
or there can be similar patterns. The example I've developed builds
the GUI based on a particular pattern. It also makes use of arrays
of things like text fields and panels to do this.
An Example. While the input error trapping and array developments are not as elegant as they probably should be, this example will demonstrate the issues of importance at present. You should call the applet TabbedPanelArrayApplet.java.
public class TabbedPanelArrayApplet extends JApplet
} // ends TabbedPanelArrayApplet
|I am also including the code for the HTML file which you should call TabbedPanelArrayApplet.html.|
<applet code="TabbedPanelArrayApplet.class" width=300 height=200>
|When you initially run the program you should get a JOptionPane asking you for how many client stations you need.|
|The GUI should look like the following.|
|Notice how each panel is essentially the same to the
user's perspective except for the tab that tells them which station they
are working with.
There are other things about the code that we will discuss in class.