So I've started my own little project were I am to build a simple text editor mainly using JPanel components. For now I've set my sizes like this:
tfMain.setPreferredSize(new Dimension(550,650));
It works, but it doesn't scale very well. If I resize the JFrame all my components get's moved around, trying to fit. And my tfMain stays the same as I have set it to 550x650. So, to be clear; When you start the program, my tfMain should be 550x650. If I make the window smaller, it should become smaller, and If I make the window bigger it should get bigger.
To as the problem that the buttons are moving around I think has to do with my Layout. Right Now I'm using BorderLayout, but I think that Box or Grid might be better.
Edit: I seemed to solve the problem with the components flying around with the help of GridLayout. It did however add some padding, so I'm not sure what's up with that. Here is my code so far:
public class Viewer extends JPanel {
private Controller controller;
private JPanel jpEverything = new JPanel();
private JTextArea taMain = new JTextArea();
public Viewer(Controller controller, ButtonPanel buttonPanel){
this.controller = controller;
jpEverything.setLayout(new BoxLayout(jpEverything,BoxLayout.Y_AXIS));
setPreferredSize(new Dimension(500,600));
taMain.setPreferredSize(new Dimension(400,500));
jpEverything.add(buttonPanel);
jpEverything.add(taMain);
add(jpEverything);
}
}