java - How do Mnemonics work with Radio Buttons -


i expecting when use alt+mnemonic related radio button become focused , selected. expectations based on knowledge of how mnemonics work in swing. expectation wrong?

in example code below set number of each radio button mnemonic.

  1. "option 1" selected when program starts.
  2. when use alt+3, program beeps @ me, mnemonics become underlined , "option 3" becomes focused not selected. gui looks this:

http://i.stack.imgur.com/ip3om.png

  1. if type 2, "option 2 becomes focused, not selected.

here code:

import javafx.application.application; import javafx.stage.stage; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.scene.image.*; import javafx.scene.input.*; import javafx.scene.effect.*; import javafx.scene.paint.*; import javafx.beans.value.*; import javafx.geometry.*;  import javafx.event.*;  public class radiobuttonsscce extends application {     public parent createscene()     {         togglegroup group = new togglegroup();          radiobutton rb1 = new radiobutton( "option _1" );         rb1.setuserdata("option 1 selected");         rb1.settogglegroup( group );          radiobutton rb2 = new radiobutton( "option _2" );         rb2.setuserdata("option 2 selected");         rb2.settogglegroup( group );          radiobutton rb3 = new radiobutton( "option _3" );         rb3.setuserdata("option 3 selected");         rb3.settogglegroup( group );          vbox root = new vbox(5);         root.setalignment(pos.center);         root.getchildren().addall(rb1, rb2, rb3);          changelistener<toggle> cl = new changelistener<toggle>()         {             @override             public void changed(observablevalue<? extends toggle> ov, toggle old_toggle, toggle new_toggle)             {                 if (group.getselectedtoggle() != null)                 {                     string text = group.getselectedtoggle().getuserdata().tostring();                     system.out.println( text );                 }             }         };         group.selectedtoggleproperty().addlistener(cl);          rb1.setselected( true );          return root;     }      @override     public void start(stage primarystage)     {         scene scene = new scene(createscene(), 125, 125);         primarystage.setscene(scene);         primarystage.settitle("radio button sscce");         primarystage.show();     }      public static void main(string[] args)     {         launch(args);     } } 

i have found in order invoke mnemonic have to:

  1. press , release alt key. mnemonic of each radio button underlined.
  2. press number , radio button becomes focused. however, need use space bar select radio button.

why need press space bar? should radio button not selected when mnemonic pressed?

also, why can't use alt+mnemonic single key combination select radio button?

is code wrong?

edit:

the action key selecting radio button. created generic action shared buttons:

eventhandler<actionevent> onaction = new eventhandler<actionevent>() {     @override     public void handle(actionevent e)     {         radiobutton button = (radiobutton)e.getsource();         button.setselected(true);     } };  rb1.setonaction( onaction ); rb2.setonaction( onaction ); rb3.setonaction( onaction ); 

since radio buttons part of button group didn't want ability unselect button.

the mnemonic in javafx fires actionevent targeted @ registered node. in case of radiobutton, actionevent doesn't toggle selection. can add generic handler radiobutton toggle on actionevent (assuming javafx 8).

rb1.setonaction(event -> rb1.setselected(!rb1.isselected())); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -