-
Bug
-
Resolution: Fixed
-
P4
-
1.1.2, 1.1.6, 1.3.0
-
beta
-
generic, sparc
-
solaris_2.5, solaris_2.6, solaris_7
CardLayout uses show/hide, not setVisible. I want to interpose on
setVisible, but setVisible calls show and not vice-versa. This means
that if I want to interpose on CardLayout cards being made visible I have
to interpose on show, not setVisible. I can do this, but I do not luike
being forced to use a deprecated method.
-------------
One more licensee wnat this to be fixed. See the test attached test case and the code comments.
We have run into a problem with the implementation of CardLayout. All its
methods to change which Component is showing (first, last, next, previous,
and show) call directly into Component's deprecated hide and show methods,
rather than to the new setVisible method. The result of this defect is that
the setVisible method of the Components being hidden or shown is never
called by the CardLayout. It is important to Novell that this bug be fixed
in the forthcoming release of the JDK.
Thanks
Jim Thatcher <###@###.###>
Senior Software Engineer
Novell, Inc.
Example Test Case
=================
import java.awt.*;
import java.awt.event.*;
import java.awt.AWTEvent;
public class TestFrame extends Frame implements ActionListener
{
public Panel aPanel;
public TestPanel pageRed;
public TestPanel pageGreen;
public TestPanel pageBlue;
public MenuItem mi;
public CardLayout theCardLayout;
public TestFrame()
{
super( "Test Frame - from Novell, Inc." );
setBackground( Color.black );
setLayout( new BorderLayout(5,5) );
enableEvents( AWTEvent.WINDOW_EVENT_MASK );
MenuBar mb = new MenuBar();
Menu fileMenu = new Menu( "File" );
Menu pageMenu = new Menu( "Pages" );
mi = new MenuItem( "Exit" );
mi.addActionListener( this );
fileMenu.add( mi );
mi = new MenuItem( "Red" );
mi.addActionListener( this );
pageMenu.add( mi );
mi = new MenuItem( "Green" );
mi.addActionListener( this );
pageMenu.add( mi );
mi = new MenuItem( "Blue" );
mi.addActionListener( this );
pageMenu.add( mi );
mb.add( fileMenu );
mb.add( pageMenu );
setMenuBar( mb );
aPanel = new Panel();
theCardLayout = new CardLayout();
aPanel.setLayout( theCardLayout );
pageRed = new TestPanel( "PageRed", Color.red );
pageGreen = new TestPanel( "PageGreen", Color.green );
pageBlue = new TestPanel( "PageBlue", Color.blue );
aPanel.add( "PageRed", pageRed );
aPanel.add( "PageGreen", pageGreen );
aPanel.add( "PageBlue", pageBlue );
add( "Center", aPanel );
setSize( getPreferredSize());
}
public Insets getInsets()
{
return new Insets( 47, 9, 9, 9 );
}
public void actionPerformed( ActionEvent e )
{
if( e.getActionCommand().equals( "Exit" ))
{
dispose();
System.exit(0);
}
else if( e.getActionCommand().equals( "Red" ))
{
theCardLayout.show( aPanel, "PageRed" );
}
else if( e.getActionCommand().equals( "Green" ))
{
theCardLayout.show( aPanel, "PageGreen" );
}
else if( e.getActionCommand().equals( "Blue" ))
{
theCardLayout.show( aPanel, "PageBlue" );
}
}
protected void processEvent( AWTEvent event )
{
if( event instanceof WindowEvent )
{
if( event.getID() == WindowEvent.WINDOW_CLOSING )
{
dispose();
System.exit(0);
}
}
super.processEvent( event );
}
static public void main( String[] args )
{
TestFrame theTestFrame = new TestFrame();
theTestFrame.setVisible( true );
}
}
class TestPanel extends Panel
{
private String pageName;
private Dimension pageSize = new Dimension( 600, 400 );
public TestPanel( String pageName, Color pageColor )
{
this.pageName = pageName;
setBackground( pageColor );
}
// tried to override the method setVisible() in component, but because CardLayout ca
lls
// the deprecated show() and hide() directly
// instead of calling the new method setVisible(), this method never gets called! --
oops!
public void setVisible( boolean condition )
{
super.setVisible( condition );
System.out.println( "setVisible( " + "condition" + " ) was called - " + page
Name );
}
// I shouldn't have to override a deprecated method to get this functionality!!!
public void show()
{
super.show();
System.out.println( "Oops, show was called directly by CardLayout - " + page
Name );
}
// I shouldn't have to override a deprecated method to get this functionality!!!
public void hide()
{
super.hide();
System.out.println( "Oops, hide was called directly by CardLayout - " + page
Name );
}
public Dimension getPreferredSize()
{
return pageSize;
}
}
setVisible, but setVisible calls show and not vice-versa. This means
that if I want to interpose on CardLayout cards being made visible I have
to interpose on show, not setVisible. I can do this, but I do not luike
being forced to use a deprecated method.
-------------
One more licensee wnat this to be fixed. See the test attached test case and the code comments.
We have run into a problem with the implementation of CardLayout. All its
methods to change which Component is showing (first, last, next, previous,
and show) call directly into Component's deprecated hide and show methods,
rather than to the new setVisible method. The result of this defect is that
the setVisible method of the Components being hidden or shown is never
called by the CardLayout. It is important to Novell that this bug be fixed
in the forthcoming release of the JDK.
Thanks
Jim Thatcher <###@###.###>
Senior Software Engineer
Novell, Inc.
Example Test Case
=================
import java.awt.*;
import java.awt.event.*;
import java.awt.AWTEvent;
public class TestFrame extends Frame implements ActionListener
{
public Panel aPanel;
public TestPanel pageRed;
public TestPanel pageGreen;
public TestPanel pageBlue;
public MenuItem mi;
public CardLayout theCardLayout;
public TestFrame()
{
super( "Test Frame - from Novell, Inc." );
setBackground( Color.black );
setLayout( new BorderLayout(5,5) );
enableEvents( AWTEvent.WINDOW_EVENT_MASK );
MenuBar mb = new MenuBar();
Menu fileMenu = new Menu( "File" );
Menu pageMenu = new Menu( "Pages" );
mi = new MenuItem( "Exit" );
mi.addActionListener( this );
fileMenu.add( mi );
mi = new MenuItem( "Red" );
mi.addActionListener( this );
pageMenu.add( mi );
mi = new MenuItem( "Green" );
mi.addActionListener( this );
pageMenu.add( mi );
mi = new MenuItem( "Blue" );
mi.addActionListener( this );
pageMenu.add( mi );
mb.add( fileMenu );
mb.add( pageMenu );
setMenuBar( mb );
aPanel = new Panel();
theCardLayout = new CardLayout();
aPanel.setLayout( theCardLayout );
pageRed = new TestPanel( "PageRed", Color.red );
pageGreen = new TestPanel( "PageGreen", Color.green );
pageBlue = new TestPanel( "PageBlue", Color.blue );
aPanel.add( "PageRed", pageRed );
aPanel.add( "PageGreen", pageGreen );
aPanel.add( "PageBlue", pageBlue );
add( "Center", aPanel );
setSize( getPreferredSize());
}
public Insets getInsets()
{
return new Insets( 47, 9, 9, 9 );
}
public void actionPerformed( ActionEvent e )
{
if( e.getActionCommand().equals( "Exit" ))
{
dispose();
System.exit(0);
}
else if( e.getActionCommand().equals( "Red" ))
{
theCardLayout.show( aPanel, "PageRed" );
}
else if( e.getActionCommand().equals( "Green" ))
{
theCardLayout.show( aPanel, "PageGreen" );
}
else if( e.getActionCommand().equals( "Blue" ))
{
theCardLayout.show( aPanel, "PageBlue" );
}
}
protected void processEvent( AWTEvent event )
{
if( event instanceof WindowEvent )
{
if( event.getID() == WindowEvent.WINDOW_CLOSING )
{
dispose();
System.exit(0);
}
}
super.processEvent( event );
}
static public void main( String[] args )
{
TestFrame theTestFrame = new TestFrame();
theTestFrame.setVisible( true );
}
}
class TestPanel extends Panel
{
private String pageName;
private Dimension pageSize = new Dimension( 600, 400 );
public TestPanel( String pageName, Color pageColor )
{
this.pageName = pageName;
setBackground( pageColor );
}
// tried to override the method setVisible() in component, but because CardLayout ca
lls
// the deprecated show() and hide() directly
// instead of calling the new method setVisible(), this method never gets called! --
oops!
public void setVisible( boolean condition )
{
super.setVisible( condition );
System.out.println( "setVisible( " + "condition" + " ) was called - " + page
Name );
}
// I shouldn't have to override a deprecated method to get this functionality!!!
public void show()
{
super.show();
System.out.println( "Oops, show was called directly by CardLayout - " + page
Name );
}
// I shouldn't have to override a deprecated method to get this functionality!!!
public void hide()
{
super.hide();
System.out.println( "Oops, hide was called directly by CardLayout - " + page
Name );
}
public Dimension getPreferredSize()
{
return pageSize;
}
}