0
I need to align the text of JButton
the left of the icon as I do?
I tried to use the method
button.setHorizontalAlignment(SwingConstants.LEFT);
but this method does not align the text the way I want it.
It’s getting like the first but I want it to look like the second:
Here is a generic code to create the button:
public void genericMethod(){
JFrame frame = new JFrame("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:
The answer you already gave in the question, is just the
button.setHorizontalAlignment(SwingConstants.LEFT);
You’re not even using that in the code.– user28595
with this method the icon continues left even if I change the parameter to RIGHT.
– Vinicius Silva