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?
Use JRadioButton#setText() with setVerticalTextPosition(SwingConstants.BOTTOM).
JRadioButton jrb = new JRadioButton();
jrb.setText("Label");
jrb.setVerticalTextPosition(JRadioButton.BOTTOM);
jrb.setHorizontalTextPosition(JRadioButton.CENTER);

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();
}
});
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With