I would like to know how I capture the option of a radiobutton to show it in the JTable of this window?

0

// This is the window where I will show a price according to the user's options in the main window

public class VentanaResultados extends JFrame {

    public VentanaResultados() {

        Container cp = getContentPane();
        cp.setLayout(new BorderLayout());
        // Nombres de las columnas 
        final String[] Columnas = {"Familia", "Precio por día"};

        // Datos 
        Object[][] datos = {
            {"", ""}};

        JTable tabla = new JTable(datos, Columnas);

        tabla.setFont(new Font("Arial", Font.BOLD, 18));
        tabla.setRowHeight(24);

        JScrollPane jsp = new JScrollPane(tabla); // ,ver , hor) ;

        cp.add(jsp, BorderLayout.CENTER);
        setSize(500, 300);
        setVisible(true);
    }

}
    
asked by Yezer.A 10.11.2018 в 21:41
source

1 answer

2

To capture the option of a JRadioButton , one of the ways would be to implement in some way the interface ItemListener which has as abstract method itemStateChanged​(ItemEvent e) .

To generate the event we would do it with the JRadioButton and the addItemListener(ItemListener l);

method
miRadioButton.addItemListener(new ClaseQueImplementaItemListener());

Where ClaseQueImplementaItemListener() would be the receiving class of the event .

And to know the exact radiobutton pressed .. inside the method itemStateChanged ()

if (miRadioButton.isSelected()) {
        new VentanaResultados();
}

Also you could do with an anonymous class in this way ..

miRadioButton.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            new VentanaResultados();
        }
    });
    
answered by 11.11.2018 в 10:23