Ver Mensaje Individual
  #3 (permalink)  
Antiguo 16/07/2015, 05:57
Avatar de Profesor_Falken
Profesor_Falken
 
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 9 meses
Puntos: 182
Respuesta: Remarcar botón desactivado

Buenas,

Entiendo que hablas de Java/Swing.

Supongo que habras hecho un grupo(ButtonGroup) de JButton. Por defecto no swing no aporta ninguna decoracion para senalar el boton pulsado, asi que efectivamente tienes que detectarlo y controlarlo tu.
Otra opcion es utilizar un grupo de JToggleButton. Ejemplo rapido:

Código Java:
Ver original
  1. public class JavaButtonGroupExamplePanel extends JPanel {
  2.  
  3.     BorderLayout borderLayout1 = new BorderLayout();
  4.     JPanel jPanel1 = new JPanel();
  5.     JToggleButton button1 = new JToggleButton();
  6.     JToggleButton button2 = new JToggleButton();
  7.     JToggleButton button3 = new JToggleButton();
  8.     ButtonGroup buttons = new ButtonGroup();
  9.  
  10.     public JavaButtonGroupExamplePanel() {
  11.  
  12.         try {
  13.             jbInit();
  14.         } catch (Exception ex) {
  15.             ex.printStackTrace();
  16.         }
  17.         JFrame frame = new JFrame();
  18.         frame.add(this);
  19.         frame.setLocationRelativeTo(null);
  20.         frame.setSize(400, 300);
  21.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.         frame.setVisible(true);
  23.     }
  24.  
  25.     void jbInit() throws Exception {
  26.         this.setLayout(borderLayout1);
  27.         jPanel1.setLayout(null);
  28.         button1.setText("Button 1");
  29.         button1.setBounds(new Rectangle(132, 75, 91, 23));
  30.         button2.setText("Button 2");
  31.         button2.setBounds(new Rectangle(132, 100, 91, 23));
  32.         button3.setText("Button 3");
  33.         button3.setBounds(new Rectangle(132, 124, 91, 23));
  34.         this.add(jPanel1, BorderLayout.CENTER);
  35.         jPanel1.add(button1, null);
  36.         jPanel1.add(button2, null);
  37.         jPanel1.add(button3, null);
  38.  
  39.         // this is where the radio buttons are added to the button group
  40.         buttons.add(button1);
  41.         buttons.add(button2);
  42.         buttons.add(button3);
  43.     }
  44.  
  45.     public static void main(String[] args) {
  46.         EventQueue.invokeLater(() -> new JavaButtonGroupExamplePanel());
  47.     }
  48. }



En cualquier caso, para ese tipo de funcionalidad se utilizan generalmente los JRadioButton.

Un saludo
__________________
If to err is human, then programmers are the most human of us