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

swing buttons

 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic