Well, I have this code:
static class things implements ActionListener {
public void actionPerformed (ActionEvent e) {
JFrame frame4 = new JFrame("More things");
frame4.setVisible(true);
frame4.setResizable(true);
frame4.setSize(1366,730);
JPanel panel = new JPanel();
JLabel label = new JLabel("<html>One thing more</html>");
label.setVerticalAlignment(SwingConstants.BOTTOM);
label.setHorizontalAlignment(SwingConstants.RIGHT);
panel.add(label);
frame4.add(panel);
}
}
But when I run it, the JLabel with the Vertical/horizontal alignment isn't align, why?
That happens because of
LayoutManager. Read more about using differentLayoutManager's1)
JPaneluseFlowLayoutas default. Set to right aligning components for that with help of constructor.2)
JFrameuseBorderLayoutas default. Add your panel to it with parameterBorderLayout.SOUTH.3) use
frame4.setVisible(true);at the end of construction of GUI for avoiding artifacts.4)use
pack()method instead of setting size toJFrame.