Umesh Kacha
Umesh Kacha

Reputation: 13686

How to debug Java Swing Layouts

There is one method which prints layout information for particulat components. I knew one method is there but I forgot the name.

When you call that method for Swing component it displays layout information in detail for that component just like dumpstacktrace call.

Any idea? What is that method name? I read it in one book but forgot it. Or let me know some good ways to debug Java Swing layout.

Upvotes: 11

Views: 9448

Answers (3)

StanislavL
StanislavL

Reputation: 57421

When your JFrame is visible press CTRL+SHIFT+F1 and see the console output for the tree hierarchy of components and layouts.

Upvotes: 35

Aaron
Aaron

Reputation: 5979

I don't know about a specific method for this by you can do this with a key press at runtime.

Take a look at page: Troubleshooting AWT

It provides the following debugging tip:

To dump the AWT component hierarchy, press Ctrl+Shift+F1.

It also provides other tips for layout debugging under the section "Problems With Layout" and there is another section dedicated to swing "Troubleshooting Swing"

Upvotes: 8

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

Each Container (and this includes all JComponents) has a getLayout() method which will return the layout manager that has been set for this component or null if none are set (but remember that many are given default managers). You can also getComponents() to return an array of the components held. If you want to see all layout managers, you'd have to write a recursive method to go through all the components held, check that they inherit from Container and then call the above methods.

Upvotes: 2

Related Questions