#JButton sizing in Panel?

6 messages · Page 1 of 1 (latest)

turbid ravine
#

I've attempted 3-5 different means of putting buttons/components into this JPanel, but I have so far failed to find how to resize the individual entries because the panel sizes them itself.
I feel as though I have some fundamental misunderstanding of the Panel; I'll attach an example.

Here is where I struggle:

private JPanel makeButtonsPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(7, 0));

    JButton settings = new JButton("Settings");
    settings.setPreferredSize(new Dimension(100, 50)); // <---
    panel.add(settings, BorderLayout.CENTER);

    return panel;
}
    public ThisPage() {
        JFrame landing_frame = new JFrame();
        landing_frame.setPreferredSize( new Dimension(1920, 1080) ); //temporary sizes

        JPanel landing_panel = new JPanel();
        landing_panel.setLayout(new GridLayout(0, 3));

        landing_panel.add( makeButtonsPanel(), 0.0f ); // <---

        landing_frame.add(landing_panel, BorderLayout.CENTER);
        landing_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        landing_frame.setTitle("PLO");

        landing_frame.pack();
        landing_frame.setVisible(true);
    }

It may be that JPanel is the wrong tool for having customized sizes for items, maybe I'm just using the wrong LayoutManager for this?
I did see the post "JButton Sizing Not Working," but I've attempted both solutions presented there (but may have done at least one wrong).
This is my first experience with JFrames; any help would be appreciated.

smoky cobaltBOT
#

This post has been reserved for your question.

Hey @turbid ravine! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

brittle geyser
#

You're supposed not to care so much about item sizes and instead let the computer size them according to your chosen layout

#

In practice you'll just configure the layout managers to size themselves rather than indivudual items, to keep consistent alignments

#

Generally you won't guess anything. Follow tutorials