Changing a JButton text when clicked

前端 未结 3 1146
清酒与你
清酒与你 2020-12-17 04:49

I have created a class which extends JDialog, where I have some checkboxes and 3 buttons: accept, cancel, and select all.

When user clicks select all, every checkbox

3条回答
  •  有刺的猬
    2020-12-17 05:47

    The button does not disappear, it just becomes too wide to fit in the window. Just redraw the component when changing the button label :

    @Override
    public void actionPerformed(ActionEvent e) {
        if(allCheckBoxesSelected){
            allCheckBoxesSelected = false;
            allButton.setText("Select all");
        } else {
            allCheckBoxesSelected = true;
            allButton.setText("Unselect all");
            NodeSelectionCheckBoxJDialog.this.pack();
        }
    }
    

提交回复
热议问题