How to debug Java Swing Layouts

前端 未结 3 1046
暖寄归人
暖寄归人 2020-12-01 17:02

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

相关标签:
3条回答
  • 2020-12-01 17:30

    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.

    0 讨论(0)
  • 2020-12-01 17:47

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

    0 讨论(0)
  • 2020-12-01 17:54

    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"

    0 讨论(0)
提交回复
热议问题