I am attempting to add a button to my JFrame.
I am unable to assign the JButton to a certain size.
I have tried
mJButtonOne.setPreferredSize
mjButtonOne.setMinimum/maximum
mjBUttonOne.setSize
No matter what I try the button always loads full screen.
Here is my code I am using a few methods, a make, a build, and a dostuff.
private void make() {
this.mJLabelTime = new JLabel("");
this.mJButtonOne = new JButton("");
//I have tried setting size in do stuff as well.
}
private void build(){
this.add(this.mJLabelTime);
this.add(this.mJButtonOne);
}
private void doStuff(){
this.mJLabelTime.setText(Customtime.time("HH:mm:ss"));
this.mJButtonOne.setText("BUTTON!");
this.mJButtonOne.setPreferredSize(new Dimension(1, 10));
My Main looks like this.
public static void main(String[] args) {
View view = new View();
view.setMaximumSize(new Dimension(200, 200));
view.setMinimumSize(new Dimension(200, 200));
view.setVisible(true);
System.out.println("Running app...");
//System.out.println("Goodbye World");
}
If you are not using any LayoutManager, call
setLayout(null)for yourViewclass.But it’s recommended that you pick and use a layout manager and let the layoutmanager take care of sizing components.