I need to align the text of JButton
to the left of the icon as I do?
I tried using the
button.setHorizontalAlignment(SwingConstants.LEFT);
But this method does not align the text the way I want it.
It's getting the same as the first but I want the second to be equal:
Hereisagenericcodeforcreatingthebutton:
publicvoidgenericMethod(){JFrameframe=newJFrame("JFrame Example");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JButton button = new JButton();
button.setText("GenericButton");
button.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/nextnext.png")));
button.setHorizontalAlignment(SwingConstants.RIGHT);
panel.add(button);
frame.add(panel);
frame.setSize(300, 300);
frame.setVisible(true);
}
public static void main(String s[]) {
new NewClass().genericMethod();
}
The return of the above code is: