Learner
Learner

Reputation: 161

Disadvantage of using setBounds() in Swing

I want to know is there any disadvantage to using setBounds() method in Java Swing? I have hardcoded the xy co-ordinate values to accommodate my 17-inch screen. Suppose my application is started in a 21 inch screen. Will the screen adjust automatically or will it distort? Is there any other disadvantage of using this method?

Upvotes: 2

Views: 579

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347234

is there any disadvantage of using setBounds

Yes, plenty. But most important of all, is the one you just mentioned.

You've just basically ignored one of the most powerful and useful API's in Java's UI toolkit, the layout managers.

These managers are responsible for making decisions on how best to represent you components on different screen sizes and resolutions without you having to think about.

If you decide to no longer use these layout managers, it becomes your responsibility to manage it and I don't know about you, I've got more then enough to do already.

The other problem is updating your screen. What happens when you want to add a new label. You need to go through ALL your code and figure out how much everything else needs to move around to accommodate it, including what to do when you don't have enough space.

And don't even get me started on FontMetrics :P

Upvotes: 7

Related Questions