Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4049410
Votes 5
Synopsis CardLayout uses show/hide, not setVisible
Category java:classes_awt
Reported Against 1.1.2 , 1.1.6 , kestrel-beta
Release Fixed 1.4(merlin-beta)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 02-MAY-1997
Description
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  customer  that this bug be fixed
in the forthcoming release of the JDK.

Thanks

Jim Thatcher <  xxxxx@xxxxx  >
Senior Software Engineer
 customer , 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  customer , 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;
        }
}
Work Around
N/A
Evaluation
  xxxxx@xxxxx   1997-12-19
The bug report is accurate. I've fixed the problem and will write a test
case.

---------

11/29/99   xxxxx@xxxxx   -- still does the same thing, even in kestrel-RA 
(1.3.0 build "I").


Fix is easy.  
  xxxxx@xxxxx   2000-08-25
Comments
  
  Include a link with my name & email   

Submitted On 13-FEB-1998
serrot
This is a very annoying problem when using the 
CardLayout in the WorkShop 2.0 Visual GUI developer.
If there really is a fix for it, I would like to have it.
Please let me know how I can get it.
atorres@arl.mil


Submitted On 03-APR-1998
phyde
This problem still exists in the 1.2beta3 source
and really should be fixed thoughout the AWT.


Submitted On 30-JAN-2003
genepi
Still not fixed in 1.3.1_01!
Should be easy to fix, with the other "visibility" problems in 
CardLayout...



PLEASE NOTE: JDK6 is formerly known as Project Mustang