• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JTabbedPane display Problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello:
I have a JTabbedPane with 2 Tabs. Each Tab is subdivided with several JPanels. On the BOTTOM (initially unselected) tab their is a Choice(Drop Down Menu). The problem is when my application starts the choice is visible, eventhough it's tab is not selected. This problem remains until I select it's tab and then reselect the original.
Anyone have this problem before
Thanks!
Update:
I found a piece of simple code on the net, it does the same thing. When I run this program I see the 2 password fields on page1 (correct), but I also see the 3 TextAreas on page3(incorrect). Incorrect, can someone run the code and tell me if they also see the TextAreas on start-up. Is this a problem with my enviroment setup?
Code:
import java.awt.*;
import javax.swing.*;
class TabbedPaneExample
extends JFrame
{
privateJTabbedPane tabbedPane;
privateJPanelpanel1;
privateJPanelpanel2;
privateJPanelpanel3;

public TabbedPaneExample()
{
// NOTE: to reduce the amount of code in this example, it uses
// panels with a NULL layout. This is NOT suitable for
// production code since it may not display correctly for
// a look-and-feel.

setTitle( "Tabbed Pane Application" );
setSize( 300, 200 );
setBackground( Color.gray );
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create the tab pages
createPage1();
createPage2();
createPage3();
// Create a tabbed pane
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "Page 1", panel1 );
tabbedPane.addTab( "Page 2", panel2 );
tabbedPane.addTab( "Page 3", panel3 );
topPanel.add( tabbedPane, BorderLayout.CENTER );
}
public void createPage1()
{
panel1 = new JPanel();
panel1.setLayout( null );
JLabel label1 = new JLabel( "Username:" );
label1.setBounds( 10, 15, 150, 20 );
panel1.add( label1 );
JTextField field = new JTextField();
field.setBounds( 10, 35, 150, 20 );
panel1.add( field );
JLabel label2 = new JLabel( "Password:" );
label2.setBounds( 10, 60, 150, 20 );
panel1.add( label2 );
JPasswordField fieldPass = new JPasswordField();
fieldPass.setBounds( 10, 80, 150, 20 );
panel1.add( fieldPass );
}
public void createPage2()
{
panel2 = new JPanel();
panel2.setLayout( new BorderLayout() );
panel2.add( new JButton( "North" ), BorderLayout.NORTH );
panel2.add( new JButton( "South" ), BorderLayout.SOUTH );
panel2.add( new JButton( "East" ), BorderLayout.EAST );
panel2.add( new JButton( "West" ), BorderLayout.WEST );
panel2.add( new JButton( "Center" ), BorderLayout.CENTER );
}
public void createPage3()
{
panel3 = new JPanel();
panel3.setLayout( new GridLayout( 3, 2 ) );
panel3.add( new JLabel( "Field 1:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 2:" ) );
panel3.add( new TextArea() );
panel3.add( new JLabel( "Field 3:" ) );
panel3.add( new TextArea() );
}
// Main method to get things started
public static void main( String args[] )
{
// Create an instance of the test application
TabbedPaneExample mainFrame= new TabbedPaneExample();
mainFrame.setVisible( true );
}
}

[This message has been edited by Johnny Clark (edited June 29, 2001).]
 
Johnny Clark
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I came up with a work around myself, in case someone has the same problem
1.Set the "under"components with setVisible(false);
2.after creating tabbed Pane add a changelistener with something like:
tabbedPane.addChangeListener(new TabListener());
3. write a subclass of ChangeListener which:
listens for the correct tab then,
sets the underComponents visible with setVisible(true),
then removes itself so that it will never be called again.
class TabListener implements ChangeListener
{
public void stateChanged (ChangeEvent e)
{
JTabbedPane tp = (JTabbedPane)e.getSource();
JPanel p = (JPanel)tp.getSelectedComponent();
if(p == commentPanel)
{
commentPanel.displayComponents();//setVisibleTrue
logicalTabbedPane.removeChangeListener(this); //removes itself
}
}
}
thanks
Johnny
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic