• Post Reply Bookmark Topic Watch Topic
  • New Topic

swing buttons

 
preethi Ayyappan
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

I tried to add swing buttons in a jpanel using flowlayout(instead of grid layout) and then i added this panel to a container with border layout to the south.but the page is blank.here is my code

public void init() {
resize(150,475);
Container content = getContentPane();
content.setLayout(new BorderLayout());
JPanel panel=new JPanel(new FlowLayout());


callback.setActionCommand("callback");
callback.addActionListener(this);
panel.add(callback);
callback.setBackground(Color.pink);
noanswer.setActionCommand("noanswer");
noanswer.addActionListener(this);
panel.add(noanswer);
noanswer.setBackground(Color.pink);
content.add(panel, BorderLayout.SOUTH);
}

Is this code correct?if not pls help me with some codes

Thanks
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code looks ok to me, presuming some things about the code
you haven't shown us, like that something calls init() and that
something instantiates the JButtons.
 
Nacho Espinosa
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Would you put your entire code?

Where is the method setVisible(true) in your code)?

Probably setVisible() is call before than init().
 
rachana rayaguda
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this

JFrame frame=new JFrame();
frame.setSize(150,475);
frame.getContentPane().add(BorderLayout.SOUTH, panel);
frame.setVisible(true);

or..
in the main method...
insert this::

new yourClass().setVisible(true);
[ October 16, 2007: Message edited by: rachana rayaguda ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!