• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding controls to jpanel at runtime problem

 
nesma abd el mawla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to add jlabel to a jpanel at runtime and Here's My code but it doesn't work :



Thanks in advance
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you using netbeans deault GroupLayout
as the layout manager?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nesma,
Welcome to the Ranch!

You need to give us more information about the problem. What is the LayoutManager you are using for the panel?
If you haven't already, I would suggest reading Using Layout Managers
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you trying to add a label when the button is pushed? That would create a very peculiar appearance. If the button is pushed many times, you would create many labels.
 
nesma abd el mawla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn , Ranganathan Kaliyur Mannar :
First thanks for replys then,
currently I don't use a layout manager but I tried to use grouplayout or borderlayout as :

jPanel1.add(b,BorderLayout.PAGE_START);

and it fails too !

Campbell Ritchie :
the aim of application is simple ladder diagram tracer ,, when i press a button a jlabel (with set icon property using .png images) will appear and draw a switch for example.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before testing this on the button click, I would suggest adding this directly before you call setVisible(true) and see if it works. That should give you a clue.
 
nesma abd el mawla
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar wrote:Before testing this on the button click, I would suggest adding this directly before you call setVisible(true) and see if it works. That should give you a clue.


Thanks for reply Ranganathan ,
I tried setting visible property to true but it doesn't solve anything ,,
the problem was Creating controls and adding it on netbeans main panel at run time needs Only "Grid or Flow Layout managers" other layout managers don't work properly and I was using the default group layout.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no no, what I was trying to say was:
normally, you will build all the controls and then call setSize() or pack() on the frame and then call setVisible(true) on the frame. So, whatever code you have in the ActionListener, just call it before you show the frame. This would help you to actually find out if that code works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic