Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Java Swing: How to set component size inside container with BoxLayout
Post Body

I'm having difficulty setting the size of the BoxLayout in Java Swing.

I want to change the height of the BoxLayout so one portion is 1/4 the size of the container and the other 3/4. I tried using: createVerticalStrut(getSize().height / 3); but this didn't work. Any help would be greatly appreciated. Thanks.

import javax.swing.*;
import javax.swing.JFrame;
import java.awt.*;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class DrawingTool extends JFrame{
    public DrawingTool(){


        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); //Exits out of application
        setTitle("Shape Drawing Tool");

        paintComponents(null);
        setSize(300, 300);

        Box horizontalBox1,horizontalBox2;
        JPanel panel1,panel2;
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Container contentPane = getContentPane();
        //contentPane.setLayout(new BoxLayout());

        horizontalBox1 = Box.createVerticalBox();
        horizontalBox1.createVerticalStrut(getSize().height / 3);

        panel1 = new JPanel(new GridLayout(0,1));
        panel1.add(horizontalBox1);
        panel1.add(Box.createHorizontalGlue());
        //horizontalBox1.
        panel1.setBorder(BorderFactory.createTitledBorder("Selection Area"));
        contentPane.add(panel1);

        horizontalBox2 = Box.createVerticalBox();
        horizontalBox2.createVerticalStrut(getSize().height / 1);
        //(getSize().height/4);
        panel2 = new JPanel(new GridLayout(0,1));
        panel2.add(horizontalBox2);
        panel2.setBorder(BorderFactory.createTitledBorder("Draw Area"));
        contentPane.add(panel2,BorderLayout.SOUTH);
        setVisible(true);
    }
    public static void main(String[] args) {
        DrawingTool dt=new DrawingTool();



    }
}

Output: https://imgur.com/a/NFZXkgE

What it's supposed to look like: https://imgur.com/a/3ssEbph

Author
Account Strength
60%
Account Age
3 years
Verified Email
Yes
Verified Flair
No
Total Karma
26
Link Karma
16
Comment Karma
10
Profile updated: 1 day ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago