0

I have a JFrame with GridBagLayout. On this frame I have JToolBar and JPanel. The problem appeared when I dropped tool bar back. In an answer to JToolBar IllegalArgumentException when dropped back into GridBagLayout it says that the container for tool bar must be with BorderLayout. Ok, I thought and added one more panel (with BorderLayout) to frame and tool bar to panel. So I have

[JFrame [JPanel1[JToolBar]] [JPanel2]]

Everything works. But now I have a problem - I can't set JPanel1 height so it to be equal to tool bar height and to disappear and appear. I only have weighty as I see, but it's coefficient.

How to solve it?

Community
  • 1
  • 1
  • 1) For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete and Verifiable Example). 2) Provide ASCII art (or an image with a simple drawing) of the GUI as it should appear in smallest size and (if resizable) with extra width/height. – Andrew Thompson Apr 30 '14 at 09:21
  • @StanislavL All emails on your site are broken. Please update information how to contact with you. –  Apr 30 '14 at 12:28
  • @Andrew Thompson Thank you for help. How can I connect to this person about his code http://java-sl.com/tip_multiple_floatable_toolbars.html ? Can't I do it via stackoverflow? –  Apr 30 '14 at 12:42
  • @Andrew Thompson And again thank you! –  Apr 30 '14 at 12:51

1 Answers1

3

The default LayOut of a JFrame is BorderLayout, You just add (set) the JToolBar to JFrame as BorderLayout.NORTH and add JPanel as BorderLayout.CENTER. Set JPanel layout as GridBagLayout and do what you want with it.

I think this is you are looking for.

A Stranger
  • 551
  • 2
  • 11
  • Thank you for your time, nut I need GridBagLayout –  Apr 30 '14 at 09:29
  • 1
    @Andrew Thompson good one :-) this is [available for users with rep >50](http://stackoverflow.com/help/privileges/comment) – mKorbel Apr 30 '14 at 10:33
  • 1
    @Andrew Thompson two upvotes by two *** here :-) you have to know that I'm big fan of *** here, starting with meta community, they won everything, idio*** rulles, phaaaa (for rest or readers discusion by two users without limits) – mKorbel Apr 30 '14 at 10:56
  • BTW - noting this is now the accepted answer prompted me to delete some noise. Good call! :) BTW - welcome to the 'heady world' of those that can comment on any question or answer. ;) – Andrew Thompson Apr 30 '14 at 12:56
  • Thanks Andrew Thompson and mKorbel. – A Stranger May 02 '14 at 04:30