Zunon
Zunon

Reputation: 137

How do I set box layout for a nameless JFrame?

Ok I am trying to setLayout as BoxLayout for a nameless jFrame, what do I put in place instead of 'WhatDoIPutHere?'

import javax.swing.BoxLayout;
import javax.swing.JFrame;

public class InterestCalculator extends JFrame{

    private static final long serialVersionUID = 1L;

    public static void main(String [] args) {
        InterestCalculator comp = new InterestCalculator();
        comp.FrameHandler();
    }

    public void FrameHandler() {

        setTitle("Template");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BoxLayout(WhatDoIPutHere?, BoxLayout.Y_AXIS));
        pack();
        setVisible(true);
    }
}

Upvotes: 1

Views: 86

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168835

  • Create a JPanel
  • Set the box layout to the panel
  • Add the panel to the frame.

As an aside, don't extend JFrame unless changing existing functionality or adding new functionality.

Upvotes: 4

Related Questions