• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting properties in runtime  RSS feed

 
TAnvir das
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hav tried to make a program which takes value from a Jcombobox and make some JLabel/JButton dynamically at runtime
setting the Title of the JLabel according to the combobox values.My code is as follows-




Now the problem is only the first JLabel is set in the panel.The setbounds(only- Y) property of each new JLabel is
incremented to get a new position in the panel but it didn't work. Any other property setting works except the bounds.I also call pnl.removeall() before calling my method to refresh the panel.But nothing works. PLs help me.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tanvir,

Welcome to JavaRanch

I will move this to our Swing forum where you might get an answer.
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by TAnvir das:




Now the problem is only the first JLabel is set in the panel.


Are you sure? Because in the code you posted the variable y never changes from its default value of 0, so I would guess all the labels are placed on top of each other. That might explain why you can only see one of them.

btw, is there a reason you are using null layout manager? I don't recommend it. And you wouldn't have to worry about setBounds() at all if you were using a suitable layout manager instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!