0

I used the internet as a resource to help me make a JButton but for some reason I cannot get it to a normal size. I have changed the dimensions and messes around a lot but it is not working.

Here is my code:

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

public class ScreenSaver {
    public static void main(String[] args) {

        JFrame frame = new JFrame();
        JButton button = new JButton();
        JPanel panel = new JPanel();

        button.setSize(100, 100);
        panel.add(button);


        frame = new JFrame ("Screen Saver");
        frame.setSize(Toolkit.getDefaultToolkit().getScreenSize()); 
        frame.setUndecorated(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(panel);
        frame.setBackground(new Color(1.0f,1.0f,1.0f,0.1f));
        frame.setResizable(true);
        frame.setVisible(true);


    }
}
xenteros
  • 15,586
  • 12
  • 56
  • 91
Herseept72
  • 25
  • 1
  • 6

1 Answers1

0

Try to use

frame.setLayout(null);

then you can

button.setLocation(x,y);

It will help you to place Java components in the locations you want. Otherwise default Java Layout is applied to your Frame and then you cannot fully customise design!

Remember then you need to customise all components you are adding to JFrame. (setSize, setLocation to JPanel as well.)

Helvijs
  • 160
  • 13