JTabbedPane, JScrollPane, JScrollPane
JTabbedPane
- A component that lets the user switch between a group of
components
by clicking on a tab with a given title and/or icon.
- To create in Netbeans:
- From the component inspector, add JTabbedPane. In general you
will
add these to the center region of a BorderLayout, but they could
go
anywhere.
- rename the JTabbedPane
- select the JTabbedPane, right click, and add JPanels to the
JTabbedPane,
one JPanel for each tab desired. (you can also add JScrollPane and
other
objects to the JTabbedPane).
- properties to set for JTabbedPane:
- selectedIndex - initial tab to have selected (numbering from
0)
- tablayoutpolicy - wrap uses multiple lines to display tabs if
necessary,
scroll limits it to one line of tabs with a scroll capability.
- tabplacement - top (default), bottom, left, right.
- other properties you might want to set
- under other properties - font, sets the font of the tabs
- foreground - text color
- background - background color
- In order to set the names on the tabs
- select the JPanel you want to change the title of
- select the layout tab in the component inspector
- set the tab title
- Methods
- setSelectedIndex(int index) - tells the tabbed panel to display
tab
with specified index (counting from 0)
- addTab(String title, Component component) - adds component as a
new tab.
Example: - create an instance of a JPanel and add it as a tab.
JSplitPane
- Function:
JSplitPane
is used to divide two
(and
only two) Component
s. The two Component
s
are graphically
divided based on the look and feel implementation, and the two Component
s
can then be interactively resized by the user. JSplitPane uses
each components minimize, preferred size, and maximum size properties
to allocate space to them.
- Properties:
- Orientation - Vertical (one pane above, the other below),
Horizontal
(one to left, other to the right).
- reSizeWeight - number between 0 and 1, used to determine how
divide
left over space between the frames, e.g. if set to .75, then
first
pane gets 3/4 of any extra space, the second 1/4. To insure
that components within the split pane get enough space, e.g. a
form is a certain
size, then you'll need to set the both the preferred size and the
minimum
size property of the components contained in the JSplitPane.
- Methods:
- You probably won't need to call any of them
- To Create:
- Add a JSplitPane anywhere you'd add a JPanel
- Rename the JSpitPane to a useful name
- Set its properties (Orientation and resizeWeight)
- Right click on the JSplitPane in the component inspector and
use
the Add from palette to add 2 components (JPanels, JScrollPanes,
JTabbedPanes,
JTextArea, JTables,etc).
- Note, you will probably want to set the preferred size
and/or minimize for the components you add to a split pane.
JScrollPane
- Function: It provides scroll bar support to other
objects.
Add it to a panel, then add the object that you want scroll bars into
the
JScrollPane. Most likely you'll want to add scroll bars to JTextArea,
JTable,
or JList.
- Properties:
- Horizontal and Vertical scroll policy (always, never,
as-needed)
- Border - (for good effect, try compound border using titled
and
beveled)
- Methods:
- you probably won't have any need to write code to directly
access
a JScrollPane, it pretty much takes care of itself
- Events:
- you probably won't need to handle scroll pane events