I am playing around with Java GUIs, and I came across JLabel.setVerticalAlignment
. I have set something up so that curlLeft and curlRight would go to the corners. However, it does not seem to have ny effect. Why is that so?
private void prepareGUI() throws IOException {
mainFrame = new JFrame("Holy Bible");
mainFrame.setSize(700, 500);
mainFrame.setLayout(new GridLayout(1, 2));
mainFrame.setLocationRelativeTo(null);
mainFrame.setIconImage(new ImageIcon(getClass().getResource("/assets/bible/textures/icon.png")).getImage());
mainFrame.getContentPane().setBackground(Color.WHITE);
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent) {
System.exit(0);
}
});
mainFrame.addKeyListener(this);
leftPanel = new JPanel();
leftPanel.setBackground(Color.WHITE);
leftPanel.setLayout(new FlowLayout());
rightPanel = new JPanel();
rightPanel.setBackground(Color.WHITE);
rightPanel.setLayout(new FlowLayout());
leftLabel = new JLabel("", JLabel.CENTER);
leftLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
leftPanel.add(leftLabel);
rightLabel = new JLabel("", JLabel.CENTER);
rightLabel.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
rightPanel.add(rightLabel);
leftCurl = new JLabel();
leftCurl.setHorizontalAlignment(JLabel.LEFT);
leftCurl.setVerticalAlignment(JLabel.BOTTOM);
leftCurl.setIcon(new ImageIcon(getClass().getResource("/assets/bible/textures/curlleft15.png")));
leftPanel.add(leftCurl);
rightCurl = new JLabel();
rightCurl.setHorizontalAlignment(JLabel.RIGHT);
rightCurl.setVerticalAlignment(JLabel.BOTTOM);
rightCurl.setIcon(new ImageIcon(getClass().getResource("/assets/bible/textures/curlright15.png")));
rightPanel.add(rightCurl, BorderLayout.SOUTH);
mainFrame.add(leftPanel);
mainFrame.add(rightPanel);
mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Maximizes frame
mainFrame.setUndecorated(fullScreen);
mainFrame.setVisible(true);
}
All the variables needed are initialized at class level.