I'm totally new at Java, and I'm trying to write my first program..
But I've already run into the first problem that I can't seem to find the answar to at google.
I have made a JFrame and a JPanel inside of it.
I want the panel to be a specific size, but when I try to set the size of the panel, it doesn't work, and the panel just fits the size of the frame.
package proj;
import javax.swing.*;
import java.awt.*;
class Program {
Program() {
JFrame frame = new JFrame("Mit program");
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(600, 400);
frame.setResizable(false);
JPanel panel = new JPanel();
panel.setVisible(true);
panel.setSize(100,100); // <- Why doesn't this work?
panel.setBorder(BorderFactory.createLineBorder(Color.black));
frame.add(panel);
}
}
public class Proj {
public static void main(String[] args) {
new Program();
}
}