• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TabbedPane

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic