A JPanel that displays six radio buttons with labels.

A JPanel that displays six radio buttons with labels.

import java.awt.*;
import javax.swing.*;

/** A JPanel that displays six JRadioButtons. 
 *
 *.
 */

public class SixChoicePanel extends JPanel {
  public SixChoicePanel(String title, String[] buttonLabels) {
    super(new GridLayout(3, 2));
    setBackground(Color.lightGray);
    setBorder(BorderFactory.createTitledBorder(title));
    ButtonGroup group = new ButtonGroup();
    JRadioButton option;
    int halfLength = buttonLabels.length/2;  // Assumes even length
    for(int i=0; i

Permanent link to this article: http://bangla.sitestree.com/a-jpanel-that-displays-six-radio-buttons-with-labels/

Leave a Reply