lundi 29 février 2016

How to set another Items Visible when Checkbox is clicked?

I have written a frame in java swing . In it I have a checkbox . I want , that after clicking checkbox others Item will change it visibility. I was trying to do it as in code below but is not working as i wish .

public InFrm() {
    setTitle("In");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    getContentPane().setLayout(new GridLayout(1, 1, 0, 0));
    seeMe=false;


    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(0.7);
    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    getContentPane().add(splitPane);

    JPanel panel = new JPanel();
    splitPane.setLeftComponent(panel);
    panel.setLayout(null);


     JPanel panel_1 = new JPanel();
    splitPane.setRightComponent(panel_1);

    panel_1.setLayout(null);

    JLabel lblKind= new JLabel("Kind");
    lblKind.setBounds(10, 8, 33, 14);
    lblKind.setVisible(seeMe);
    panel_1.add(lblKind);

    JComboBox ChoiceOd = new JComboBox();
    ChoiceOd.setBounds(53, 5, 28, 20);
    ChoiceOd.setVisible(seeMe);
    panel_1.add(ChoiceOd);


    // more items using seeMe


    JCheckBox chckbxOd = new JCheckBox("Od");
    chckbxOd.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
          seeOd();
          }
    });
    chckbxOd.setBounds(6, 150, 97, 23);
    panel.add(chckbxOd);



}

protected void seeOd() {
    if(seeMe){
        seeMe=false;
        }
    else
    {
        seeMe=true;
    }
}




Aucun commentaire:

Enregistrer un commentaire