質問

How to make a toggle button toggled automatically when someone types anything in text field?? i am using java Net-beans

役に立ちましたか?

解決

      jToggleButton1.setSelected(true);

and if you are using netbeans go to properties of button and choose selected property mark it checked if you want someone to enter the text in the textfield then automatically let the toggle button select use like this

    private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {                                       
     jToggleButton1.setSelected(true);
    }         

他のヒント

Add a listener to the textfield and call toggleButton.setSelected(boolean selected).

   if(t.getText().length()==0){

       jToggleButton1.setSelected(true);
   }
   else if(t.getText().length()>0){

      jToggleButton1.setSelected(false);
   }

you have to check the length of the text field and then by using the if-else you can select or dis select the toggle button

int count=0;

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    for(int i=0; i<1; i++){count++;}
    count=count;
    System.out.println(count);
    if(count==1){
      System.out.println("open");
      jButton1.setText("open");
     }
    if(count==2){
      System.out.println("close");
      jButton1.setText("close");
    count=0;
    }

}

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top