简体   繁体   中英

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.

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

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM