-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
1.2.0
-
x86
-
windows_nt
Name: rk38400 Date: 05/08/98
Swing 0.7 supported multiple tabs with the same
component and exhibited perfect behavior in that
respect. Swing 1.0.1 basically worked too, though
it introduced a layout problem on resize.
However, Swing 1.0.2 completely breaks this ability.
When multiple tabs are attached to the same component,
the behavior is completely wrong: missing tabs; the
component doesn't display, etc.
What is surprising is how small the code changes are
between 1.0.1 and 1.0.2 for JTabbedPane. Below is a
test snippet that demonstrates how dramatically different
those changes behave.
Before that, you might ask "why would one want to do this?"
Well, we add a custom SingleSelectionModel to the JTabbedPane
that is linked to a network of data models driving sub-components
within a single JPanel that is added to all tabs.
Essentially, the tabs serve as a radio button with a
variant rendering (as they should have been originally
architected, IMHO).
Within the world of MVC, this should be a completely
legitimate use of JTabbedPane.
Here's the tester:
<PRE><TT>
import com.sun.java.swing.*;
import java.awt.*;
import com.sun.java.swing.JFrame;
import com.sun.java.swing.JTabbedPane;
import com.sun.java.swing.JLabel;
public class TabTester extends com.sun.java.swing.JFrame
{
public TabTester()
{
getContentPane().setLayout(new BorderLayout(0,0));
setVisible(false);
setSize(405,305);
jTabbedPane1 = new com.sun.java.swing.JTabbedPane();
getContentPane().add(jTabbedPane1);
jLabel1 = new com.sun.java.swing.JLabel("Label 1");
jTabbedPane1.addTab("First=1", null, jLabel1, null);
jLabel2 = new com.sun.java.swing.JLabel("Label 2");
jTabbedPane1.addTab("Second=2", null, jLabel2, null);
jTabbedPane1.addTab("Third=1", null, jLabel1, null);
jTabbedPane1.addTab("Fourth=2", null, jLabel2, null);
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
}
public TabTester(String sTitle)
{
this();
setTitle(sTitle);
}
public void setVisible(boolean b)
{
if (b)
setLocation(50, 50);
super.setVisible(b);
}
static public void main(String args[])
{
(new TabTester()).setVisible(true);
}
com.sun.java.swing.JTabbedPane jTabbedPane1;
com.sun.java.swing.JLabel jLabel1;
com.sun.java.swing.JLabel jLabel2;
class SymWindow extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == TabTester.this)
TabTester_WindowClosing(event);
}
}
void TabTester_WindowClosing(java.awt.event.WindowEvent event)
{
setVisible(false); // hide the Frame
dispose(); // free the system resources
System.exit(0); // close the application
}
}
</TT></PRE>
- JJ
(Review ID: 29924)
======================================================================