• 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

Help adding JButton to a JPanel from another method!

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a bit of a problem, I am trying to add some JButtons into a JPanel from a method call that is triggered by a buttons actionlistener, the problem i have got is when it comes to adding the button it does not show on the JPanel but if i get the component count of the JPanel it shows it as being there. I am using Netbeans 6.5 and using a FlowLayout for my JPanel, this is what i have

in my first JPanel that i have i add buttons to it when the JPanel is created and this works fine



As you can see i created my own actionlistener for these buttons which i attach to the buttons and this is what it looks like



In my actionlistener i then call a few methods that are in the PosTeller class as this is where my JPanel sits, here are the methods



The problem is when it gets to the addToCatPane() and i create the buttons to add to the productsPane absolutly nothing happens, nothing gets displayed!! but the component count shows that there are components there, i have called rePaint() reValidate() inValidate() etc etc and nothing seems to make them display....

Please can someone help me
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
normally when adding or removing components from a visible swing container you need both
container.revalidate();
container.repaint();

not always, but most times, both are required
 
Brendon Randall
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply, i have just tried that, this is what i did



But still no luck the buttons do not show
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you would need to post a compilable program, otherwise it's just a guessing game.

if productsPane's layoutmanger is null, your problem is there
if cat.size() < 1 your problem is there
etc

in posting a compilable program, get rid of the unnecessary stuff.
you're trying to get a JButton to appear, so the button's font, actionCommand,
actionListener etc are not part of the problem

reply
    Bookmark Topic Watch Topic
  • New Topic