문제

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