Reputation: 41
I have added buttons to JToolBar and the JToolBar is inside a JPanel. The toolbar is always placed on the top center of panel. But I want to position the toolbar on top left of the panel. Can anyone tell how I can position the toolbar properly? Thanks
Upvotes: 0
Views: 711
Reputation: 285403
Is your JPanel using a layout manager? If not, consider having it use BorderLayout, and then add your JToolBar using that layout, likely in the BorderLayout.PAGE_START position (also known as the BorderLayout.NORTH position).
Edit: you state that you're using a BoxLayout. Consider instead using a BorderLayout and placing your toolbar as I noted above. If the rest of your GUI requires BoxLayout, then simply embed another JPanel that uses BoxLayout into the outer JPanel's BorderLayout.CENTER position, and then add your other components into the inner JPanel. By nesting JPanels, each using its own layout, you can achieve complex GUI layouts in a simple easy way.
Upvotes: 2