Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TabbedPane  RSS feed

 
Bacchi Gerem
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
while iam running the following code when i click on tab buttons optional buttons are not displaying.


import java.awt.*;
import javax.swing.*;

class Swing1 extends JFrame
{
privateJTabbedPane tabbedPane;
privateJPanelpanel1;
privateJPanelpanel2;



public Swing1()
{

setTitle( "Tabbed Pane Application" );
setSize( 300, 200 );
setBackground( Color.gray );

JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
createPage1();
createPage2();
tabbedPane = new JTabbedPane();
tabbedPane.addTab( "Page 1", panel1 );
tabbedPane.addTab( "Page 2", panel2 );
topPanel.add( tabbedPane, BorderLayout.CENTER );

}


public void createPage1() {

panel1 = new JPanel();
panel1.setLayout( null );
JRadioButton op1= new JRadioButton("English",true);
JRadioButton op2= new JRadioButton("Metric",false);
ButtonGroup bg = new ButtonGroup();
bg.add(op1);
bg.add(op2);
panel1.add(op1)
panel1.add(op2);
}

public void createPage2()
{
panel2 = new JPanel();
panel2.setLayout( null );
JRadioButton op3= new JRadioButton("America",true);
JRadioButton op4= new JRadioButton("India",false);
ButtonGroup bg1 = new ButtonGroup();
bg1.add(op3);
bg1.add(op4);
panel2.add(op3)
panel2.add(op4);
}



// Main method to get things started
public static void main( String args[] )
{
// Create an instance of the test application
Swing1 app= new Swing1();
app.setTitle("RadioBox Demo");
app.setBounds(400,300,300,200); // position frame
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setVisible(true);

}
}


Thanks
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
both createPanel() layouts are set as null, but you haven't specified
where the components are to be placed on the panel - look up setBounds()

comment out the setLayout(null) lines and they will appear.

you will be better off using a layout manager.
if you do stick with null and setBounds, see what happens when you maximize
the frame
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!