Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does setSize() causes JButton to stop working?  RSS feed

 
Tom Josephits
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JButton, but when I resize it, it always causes it to stop working. If I click it, it shows absolutely no indication that it even knows that I clicked. If I change the layout to BorderLayout or BoxLayout, it works, but then the arrangement gets thrown off. I haven't had this problem anywhere else so I have no clue what's different here.

Also, the buttons are in a nested JPanel, but when I move it up so that it's not (as) nested, it starts working again. Any idea why this is?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem. Make sure to keep it short, we don't need to see all your code.

Does your program respect Swing's single threaded rule?
 
Tom Josephits
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem. Make sure to keep it short, we don't need to see all your code.

Does your program respect Swing's single threaded rule?


The problem is, my programs gotten to a point where it is very embedded within itself so it's hard to isolate any one instance of code. On top of that, I really have no clue what's going on. Most other problems I have, I have some idea of where it's going wrong; but here, it seems like just adjusting trivial settings makes it break down.
I was hopping that this would be some kind of problem that happens enough that someone could recognize it and point out a solution.

I haven't done anything yet that involves multiple threads.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if your program has collapsed under its own weight and you can't understand it any more, then perhaps it's time to refactor it. In your case this would probably equate to starting over and rebuilding it, one piece at a time.

You might want to use code from the old version, but this time as you build the program, test it continually as you go along. That way when it stops working, you'll know that the last thing you did was the problem.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for the specific problem you mention, it's actually not a good idea to call the setSize() method on a Swing component, since Swing layout managers generally work on the preferred size and secondarily on the maximum size and minimum size.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hopefully the problem is not as simple as using mouseClicked()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!