Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Professional Java Swing-based applications implement custom Swing components to enhance their functionality and usability. For example, IDEs like Eclipse and NetBeans use an enhanced tabbed pane as a container for source code editors. This tabbed pane has a Close icon on each tab that lets you easily close individual tabs.
In this article, we present the implementation of
CloseAndMaxTabbedPane, an enhanced tabbed pane with Close and Maximize buttons. The component's look and feel is similar to Eclipse 2.1. You can
also selectively enable/disable the Close or Maximize buttons as necessary. Figure 1 illustrates the screenshot of
Figure 1. CloseAndMaxTabbedPane in action. Click on thumbnail to view full-size image.
The UML diagram in Figure 2 shows the implementation's most critical classes and how they relate to standard Java Swing classes.
Figure 2. High-level UML diagram of CloseAndMaxTabbedPane
Descriptions of the component's critical classes follow:
javax.swing.BasicTabbedPaneUI): This class is the new component's UI delegate object and is responsible for the tabbed pane's graphical aspects (including painting the Close and Maximize buttons). This class also fires events to the tabbed pane itself based on user actions and tries to be friendly with the application's current look and feel.
CloseTabbedPaneUI): This class implements a different look and feel similar to the tabbed pane found in Eclipse 2.1. It overrides a set of paint methods to implement the enhanced look and feel.
javax.swing.JTabbedPane): This class extends the Java standard
JTabbedPaneand uses the
CloseTabbedPaneUI. It also implements methods to add specific listeners (to Close and Maximize buttons) to the tabbed pane and interact with the UI.
It would be easy to add buttons if each tab were a separate Swing component. Ideally, then you would add a Close button by simply doing the following (forgetting layout aspects for the moment):
JButton closeButon = new JButton(closeButtonIcon); tab.add(closeButton);
And then adding an action listener by:
Unfortunately adding buttons is not that easy. Each tab in a tabbed pane is not a Swing component. Each tab's header (border,
title, icon) is painted by the
BasicTabbedPaneUI class. To paint our own version of the tabbed pane (i.e., to add the little buttons in the corner of each tab), we need to
extend this class and override the paint methods to actually draw the buttons. Please note that the buttons are just painted
graphics and not standard Java
Because there are no real buttons, we can't add action listeners to them. The only way to interact with these painted buttons is to add a mouse listener to the tabbed pane itself (or to one of its components). This mouse listener can then track mouse clicks or movements in the zone where the buttons are painted and fire specific events to the tabbed pane.
|Forum migration complete By Athen|
|Forum migration update By Athen|
|Rewrite to add scroll and tabplacement support By PieterVoet|
|CloseAndMaxTabbedPane: An enhanced JTabbedPane By JavaWorld|
|? By tof|
|What's up with the Tooltip's? By Anonymous|
|Maximize-Icons By LeO_Post|
|i inspired by your UI Design By paramasivam|