Reputation: 5611
I'd like to define label position of jRadioButtons on a buttonGroup on Netbeans so the label would be positioned under its radioButton. Can it be done?
Upvotes: 3
Views: 3080
Reputation: 23025
You have to use both r.setVerticalTextPosition(JRadioButton.BOTTOM);
and
r.setHorizontalTextPosition(JRadioButton.CENTER);
together. Otherwise, it will not work
import javax.swing.*;
import java.awt.*;
public class PersonFrame extends JFrame
{
public PersonFrame()
{
JRadioButton r = new JRadioButton();
r.setText("Text");
r.setVerticalTextPosition(JRadioButton.BOTTOM);
r.setHorizontalTextPosition(JRadioButton.CENTER);
JPanel testPanel = new JPanel();
testPanel.setLayout(new FlowLayout());
testPanel.add(r);
this.add(testPanel);
this.setSize(100,100);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[]args)
{
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run() {
new PersonFrame();
}
});
}
}
Upvotes: 2
Reputation: 205785
Use JRadioButton#setText()
with setVerticalTextPosition(SwingConstants.BOTTOM)
.
JRadioButton jrb = new JRadioButton();
jrb.setText("Label");
jrb.setVerticalTextPosition(JRadioButton.BOTTOM);
jrb.setHorizontalTextPosition(JRadioButton.CENTER);
Upvotes: 5