1

I want to keep the proportions for various JPane sizes upon resizing the window (e.g. 10% text box, 90% text pane, etc.) in order for complete consistency. I've been using JSplitPanes as a stopgap, but I'd like to move on from that as it's inconvenient to change and goes crazy on the slightest resize. From what I understand, GridBag would be best. However, if I'm being honest, layout managers hurt my brain, so I'd like to confirm this before I sink an ungodly amount of hours trying to understand it. I've already spent a few hours and made no progress. I've attached an image to help. If you need any elaboration, please ask. Thank you in advanceenter image description here

6
  • 10% text box, 90% text pane - there is no "text box" component. Use the proper component name so we know exactly what you are talking about. Based on your image it looks like you want to have the vertical height change, since I only see a single component on each line. If you are referring to a JTextField it makes no sense to have its vertical height change, since all you will see is extra space. The font does not change. Maybe nesting layout manager on different panels is the best approach.
    – camickr
    Commented Jul 7 at 20:45
  • 3
    GridBagLayout first allocates space at the preferred size of each component. Then you can specify the "weightY` constraint for components that you want to grow in size as the frame size increase. So only extra space is allocated in percentages. In the simple case of a JTextField and JTextPane, I would just use a BorderLayout. Add the text field to the "PAGE_START" or "PAGE_END" and the text pane to the center. Then only the text pane will grow. Read the Swing tutorial on Layout Managers for the basics.
    – camickr
    Commented Jul 7 at 20:45
  • 1
    Another option is to check out the Relative Layout
    – camickr
    Commented Jul 7 at 20:45
  • 1
    JSplitPane already has a property for proportional sizing.
    – VGR
    Commented Jul 8 at 17:36
  • @camickr Indeed only the extra space is allocated in percentages with GridBagLayout. However, I have found that if you set the preferredSize & minimumSize of a component to [0,0], then you can use the weights to obtain perfect percentages splits, regardless of the content.
    – masterxilo
    Commented Jul 13 at 13:53

0

Browse other questions tagged or ask your own question.