SetSelected()

For selecting all the text in a dynamic text field. I had
problems with the code below losing focus after the selection. I
was chasing my tail like a mad dog trying to figure it out. I
embedded the text field in a movie clip, published it as HTML,
traced it, everything, till our ARTIST said, "Why don't you try an
onRelease." Now it works like a charm. Some days I love Flash &
others well....
selectText_btn.onPress = function()
Selection.setFocus(my_txt);
Selection.setSelection(0, my_txt.text.length);
Just thought the community needed a PSA. If anybody can
enlighten me on why this works the way it does I would love to get
an explanation.

when you press your button your onPress handler will execute,
your text gets focus and then an onRelease (or some other mouse
event) will set focus back to your button.
when you use an onRelease handler your button gets focus,
your code executes, your text gets focus and you're a happy
weenie.

Similar Messages

  • Problem with setSelection and components

    Hi! I have a problem with setSelection function when there is
    any component on the stage or in the library. Just look on the
    sample
    here The first
    button sets focus and sets selection, the second one removes focus.
    It works good, but add any component to break it. Is there any
    other way to unset focus? Maybe this is the problem... Any help?
    BTW Sorry for my english :)

    Selection.setFocus(component) removes current
    selection

  • After DND AbstractButton, setSelected not work

    Recently, I got problem in DND with AbstractButton
    and would like to share my finding
    After DND an AbstractButton,
    Within the DragSourceListener.dragDropEnd
    I get the dragged AbstractButton and invoke its
    AbstractButton.setSelected(false);
    The selection still visible, nothing have been changed
    Therefore, I println the AbstractButton.isSelected();
    And the console shows "false"
    Then, I tried to invoke invalidate, revalidate, doLayout, repaint
    but the result is the same
    Finally, I called setEnabled( ! isEnabled() ) twice and it work correctly

    So you're the one who took my crystal ball, Kaj!One doesn't need any fancy gadgets to see that it's
    201 in Person.Nope, but with this crystal ball I can see that the OP
    will ask for more help, and an explanation of the
    answer. So now I'm prepared :)
    /KajUhm..... yep, that's an advantage :)

  • Why JRadioButtob.setSelected(boolean) doesn't work?

    I implement an inner class claaes ControlPanel, subclass of JPanel, which have a GroupButton of two JRadioButtons. The state of the JRadioButton will be changed according to the selected item from a JList. My code structure as follow:
    public MainClass{
    MyJList.addListSelectionListener(new ItemSelectionListener(){
    public void valueChanged(ListSelectionEvent ..){
    myControlPanel.b1.setSelected(true);
    }//end of main class
    //inner class
    class ControlPanel{
    ButtonGroup myGroup = ;
    JRadioButton b1 = ;
    JRadioButton b2 = ;
    myGroup.add(b1);
    myGroup.add(b2);
    anybody help me. Thanks!!
    Qi

    did you initialize b1 before you call setSelected(true)?

  • Has anyone gotten myTextField.setSelection(startNum, endNum); to work?

    Perhaps I'm expecting the wrong result, but I can't get myTextField.setSelection(startNum, endNum); to select text in my TextField.
    var thisText_txt:TextField = new TextField();
    thisText_txt.text = "test textfied";
    addChild(thisText_txt);
    thisText_txt.setSelection(0, 5);
    Thanks!

    I have this on the timeline:
    var selectText:SelectText = new SelectText (this);
    And I've attached the code.
    What I've found is that using the FocusEvent in a class doesn't get the result I want.  Instead using a MouseEvent on the text field works.
    Thanks!
    package {
    import flash.display.MovieClip;
    import flash.events.FocusEvent;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.text.TextField;
    public class SelectText {
    private var stage_mc:MovieClip;
    private var textField_txt:TextField;
    public function SelectText (aStage_mc:MovieClip) {
    stage_mc = aStage_mc;
    textField_txt = new TextField();
    textField_txt.text = "test textfield";
    //textField_txt.addEventListener(FocusEvent.FOCUS_IN, focusChange);
    textField_txt.addEventListener(MouseEvent.CLICK, textClick);
    stage_mc.addChild(textField_txt);
    private function focusChange (event:FocusEvent):void {
    trace(event.type);
    if (event.type == "focusIn") {
    stage_mc.stage.focus = textField_txt;
    textField_txt.setSelection(0, textField_txt.length);
    private function textClick (event:MouseEvent):void {
    stage_mc.stage.focus = textField_txt;
    textField_txt.setSelection(0, textField_txt.length);

  • JRadioButton.setSelected(false) doesn't work?

    Hey there. I usually answer questions in this forum but this time I have a question myself. I'm trying to de-select JRadioButtons in a ButtonGroup but it's not working. I've searched the forum but didn't find anything. Here's the very simple code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ButtonTest extends JFrame {
      JRadioButton rb1 = new JRadioButton("button1", true);
      JRadioButton rb2 = new JRadioButton("button2");
      ButtonGroup bgroup = new ButtonGroup();
      JButton b = new JButton("clear");
      ButtonTest() {
        b.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            clearbuttons();
        bgroup.add(rb1);
        bgroup.add(rb2);
        Container c = getContentPane();
        c.setLayout(new GridLayout(2,2));
        c.add(rb1);
        c.add(rb2);
        c.add(b);
        addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
      void clearbuttons() {
        Component [] components = getContentPane().getComponents();
        for (int i = 0; i < components.length; i++) {
          Component c = components[ i ];
    System.out.println(c);
          if (c instanceof JRadioButton) {
            JRadioButton rb = (JRadioButton) c;
            rb.setSelected(false);  // once.
            bgroup.setSelected(rb.getModel(), false);  // twice.
    System.out.println("\ncalled setSelected\n");
      public static void main (String[]a) {
        ButtonTest b = new ButtonTest();
        b.setSize(200,100);
        b.setVisible(true);
    }Anybody know why the selected button remains selected?

    The ButtonGroup ensures that one JRadioButton is always selected, at least after the first one is initially selected. The workaround to fix this is to add an additional "dummy" JRadioButton to the ButtonGroup, and have your code select it when you want to deselect the rest of the buttons. The dummy JRadioButton doesn't need to be added to the GUI or displayed, or anything.

  • SetSelected does not generate itemStateChanged event

    Hi!
    In 1.4 setSelected, on e.g. a JCheckbox, does not generate a itemStateChanged event if you set the value to the same as the checkbox already has. So if I do a setSelected(false) method call on a newly created JCheckBox instance (I have added an ItemListener), no event is generated. This is a change since 1.3.
    I have a lot of update methods that sets the initial state of my checkboxes and this changed behaviour puts me in trouble. Is there anyone that knows of a solution to this problem. One obvious one is to set every checkbox to its opposite value before setting it to its right one, but then the code gets ugly. Is there a way to make the checkbox not remember its current value.
    Thanks in advance!
    Best regards
    Lars

    Hell, how I could overseen that! Thx alot!
    I could stare for years and didn't find it :|

  • Drop down list setSelected not working

    Hi all,
    I have a drop down list bound to a database (value: int, display: string). There are two pages:
    page 1: a table with id needed for page 2 (id passed through the url)
    page 2: drop down list bounded to a database. The selected value comes from page 1.
    Problem: Even though I am getting the correct value, and am using ddList.setSelected (id), the ddList value does not change.
    I basically want to know how to program the functionality of the "selected" property in java with a table bound to a database.
    Any ideas?

    Hi There,
    Looks like a user on this thread was able to set his drop down list value dynamically, take a look
    http://forum.java.sun.com/thread.jspa?forumID=881&threadID=5055898
    here is what the user comments
    Any way I have solved my problem
    1.Change the value field of dropdown from int to string, so value field and display fields are same.
    2. dropdown1.setvalue("abc");
    this solution will only work if the value field is String.
    Hope it helps
    Thanks
    K

  • Checkboxgroup setSelected() problem

    Hi,
    I have a number items read from a .txt file into a checkboxGroup. I have problem in selecting some of them automatically. Please help me in setSelected() function code:
    //get selected automatically
             try {                   
                 int numOfLines2 = 0;
                int count2=0;
                String theLine2 = null;
                FileReader fr4 = new FileReader("C:/CreatorProjects/Npad_PAIRS_NLP.prs");
                BufferedReader br4 = new BufferedReader(fr4);
                while ((theLine2 = br4.readLine()) != null) {
                    numOfLines2++;
                fr4.close();          // close the file.
                br4.close();          // close the buffer
                FileReader fr5 = new FileReader("C:/CreatorProjects/Npad_PAIRS_NLP.prs");
                BufferedReader br5 = new BufferedReader(fr5);
                listPatientdata = new com.sun.rave.web.ui.model.Option[numOfLines2];
                while ((theLine2 = br5.readLine()) != null || count2 <= numOfLines2) {
                    listPatientdata[count2] = new Option(theLine2, theLine2);
                    if(count2<=ptftrs)      //ptftrs is predefined integer
                        checkboxGroup1.setSelected(theLine2);
                    count2++;
                } catch(Exception e) {
                e.printStackTrace();    
       }I have no problem in using the code if I want all boxes unselected initially.
    thanks in advance.
    dr.am.mohan rao

    while ((theLine2 = br5.readLine()) != null || count2 <= numOfLines2) {
    listPatientdata[count2] = new Option(theLine2, theLine2);
    if(count2<=ptftrs)      //ptftrs is predefined integer
    checkboxGroup1.setSelected(theLine2);
    count2++;         
    } catch(Exception e) {
    e.printStackTrace();     My guess is to call setSelected after adding all options to check box group. Try something like:
    String valueToSelect = null;
    while((theLine2 = br5.readLine()) != null || count <= numOfLines2) {
    listPatientdata[count2] = new Option(theLine2, theLine2);
    if(count2 <= ptftrs)
    valueToSelect = theLine2;
    count2++;
    checkboxGroup1.setSelected(valueToSelect);best regards
    Grzegorz

  • DefaultMutableTreeNode, TreePath, setSelection

    I have a DefaultMutableTreeNode, and I want that to be selected(highlighted in blue, like if a user clicked on it). I don't know how to convert that to a TreePath so I can use the JTree.setSelection( TreePath ) method.
    Are there any suggestions?
    Here is my code snippet
    JTree tree...
    FolderNode...//Special class made by me.
      protected void selectCreatedFolder(String name)
        DefaultMutableTreeNode dt = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
        Enumeration e = dt.children();
        while ( e.hasMoreElements() )
          DefaultMutableTreeNode d =  (DefaultMutableTreeNode)e.nextElement();
          FolderNode fn = (FolderNode)d.getUserObject();
          if ( fn.folderName.equals(name) )
            System.out.println( "Found folder!!! "+name );
    //          tree.setSelectionPath(); Needs a Treepath to set it
            fn.expand( d );
            model.reload( d );
            break;
      }

    Here is the working code for anyone who may query this thread in the future.
      protected void selectCreatedFolder(String name)
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
        updateTree(parent);//updates the tree
        Enumeration e = parent.children();
        while ( e.hasMoreElements() )
          DefaultMutableTreeNode child =  (DefaultMutableTreeNode)e.nextElement();
          FolderNode fn = (FolderNode)child.getUserObject();
          if ( fn.folderName.equals(name))
            tree.setSelectionPath( new TreePath( child.getPath() ) );
            return;
      }

  • Need help for JPopupMenu's setSelected method

    I have a JPopupMenu with 5 menuItems. Each time the popupmenu is shown, I want the first item to be highlighted. Right now, the items get highlighted in a cyclic order(based on the position of the mouse). I tried using setSelected but it does not seem to be working. The code snippet:
    if (evt.isPopupTrigger()) {                  
    mapPopupMenu.show(c, evt.getX(), evt.getY());
    mapPopupMenu.setSelected(menuItem0);
    menuItem0.setSelected(true);
    What am I doing wrong?

    I have 5 buttons on different areas of a frame. When the popup menu shows up on the rightclick event on the buttons, on each button's popup, a different menu item is highlighted. For a given button, the popup comes up with the same menu item highlighted. So for the button on the extreme left, the first item is highlighted. For the button in the middle, the second menu item is highlighted and so on. Once, I move the mouse, the selection changes automatically. When the popup first shows up, I want ONLY the first menuitem to be highlighted , no matter which button I select..
    Any suggestions?
    Thanks

  • JRadioButton.setSelected( false ) ?

    First of all, I just read the thread "Secret source of answers to your problems...." and want to assure anyone reading this that I have been looking at the Java API all morning and I'm ready to rip this Java textbook into shreds.
    I have a homework assignment and while I am not asking anyone to do my homework for me, I have run up against a brick wall. I have two sets of JRadioButtons (using two ButtonGroups). I also have two JButtons - one of which I want to use to clear the form, including clearing the JRadioButton selections.
    According to the API - I should be able to set a radio button's "selected" to false. But it isn't working for me.
    Here is the snippet of code I am using in my ActionListener event handler for the Clear button. All of it works except for the setSelected method call:
    if ( event.getSource() == clearButton )
        tempField.setText( "" );            // clear text field
        inCelButton.setSelected( false );  // clear radio button
        inFahButton.setSelected( false );  // selections
        inKelButton.setSelected( false );  // inButton Group
        inCelButton.setVisible( true );    // set radio buttons
        inFahButton.setVisible( true );    // to visible
        inKelButton.setVisible( true );
        outCelButton.setSelected( false ); // clear radio button
        outFahButton.setSelected( false ); // selections
        outKelButton.setSelected( false ); // outButton Group
        outCelButton.setVisible( true );   // set radio buttons
        outFahButton.setVisible( true );   // to visible
        outKelButton.setVisible( true );
        results="";                        // clear results string
        resultsLabel.setText("");          // clear results label
    }TIA
    Sheryl McKenna

    It's not necessarily true that you have to have a button selected. It only works this way when you use a buttongroup. The buttongroup insists that one button be selected when all others are off. This is the API information (Which it sounds like you are already familiar with)
    "Initially, all buttons in the group are unselected. Once any button is selected, one button is always selected in the group. There is no way to turn a button programmatically to "off", in order to clear the button group. To give the appearance of "none selected", add an invisible radio button to the group and then programmatically select that button to turn off all the displayed radio buttons. For example, a normal button with the label "none" could be wired to select the invisible radio button."
    I just wrote a simple app to test this and it worked fine for me. The button group ensures you can't select multiple buttons. After you select one, all others are automatically de-selected. If you are really set on using a group of buttons, without the buttonGroup then I would add a panel, set the layout to null and then just add the buttons. Netbeans is a great way to test your UI without writing a lot of code and see the end results quickly. It's free and it's available at:
    http://www.netbeans.org.

  • Selection Cardinality & setSelected

    Hi,
    What is selection cardinality?
    What is the difference between these2 context node methods
    wdContext.node<Context>().setLeadSelection(int);
    wdContext.node<Context>().setSelected(int, boolean );
    and How does Selection cardinality affects the setSelected  property.
    Thanks & Regards
    Veerabhadram

    Hi
    Cardinality
    ========
    The cardinality property is composed of a pair of values that control the maximum and minimum number of elements may contain at runtime.
    The cardinality property may have four possible values:
    • 0..1 Zero or one
    • 0..n Zero or more
    • 1..1 One and only one
    • 1..n One or more
    The first part of the cardinality describes the minimum number of element ’s element collection may contain. This value is either zero or one, and is stored as a Boolean value. This value can be obtained at runtime by calling the method node.getNodeInfo().isMandatory().
    The second part of the cardinality describes the maximum number of elements ’s element collection may contain. This value is either a 1 or an n (meaning many) and is stored as a Boolean value (false = 1, true = n). This value can be obtained at runtime by calling method node.getNodeInfo().isMultiple().
    If has a cardinality of 1..<something>, then it can be assumed that after the context has been initialised, there will be at least one element present in the node collection. This element is known as the default element and cannot be deleted!
    If you attempt to perform some action on a node that would violate the constraints of the cardinality, then you will get a runtime exception in the context. E.G., trying to add a second element to a node of cardinality 0..1, or trying to delete the last element from a node of cardinality 1..n.
    Thanks
    Hazrath

  • JPopupMenu - setSelected (JMenuItem)

    Hi
    I have a popup menu with a number of menu items which I add to the popupMenu. I call setSelected with one of them (not the first added) and then show. But it is always the first item that is shown as being selected, even though when I call getSelectionModel().getSelectedIndex it returns the index of the item I set to be selected.
    I can see that others have had similar problems, but haven't been able to find anyone that could answer them.

    Why do you want the menu item selected?
    This works, but may not fully answer your question. ***************************************************************************************************
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.BorderLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.UIManager;
    public class PopupTest extends JFrame implements ActionListener
    public static void main( String[] args )
    PopupTest test = new PopupTest();
    test.pack();
    test.show();
    private JPopupMenu popup;
    private JMenuItem menuItem1;
    private JMenuItem menuItem2;
    public PopupTest()
    try
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch( Exception e )
    popup = new JPopupMenu();
    menuItem1 = new JMenuItem( "Item 1");
    menuItem1.setActionCommand( "Item 1");
    menuItem1.addActionListener( this );
    menuItem2 = new JMenuItem( "Item 2");
    menuItem2.setActionCommand( "Item 2");
    menuItem2.addActionListener( this );
    popup.add( menuItem1 );
    popup.add( menuItem2 );
    JButton button = new JButton("Button 1");
    button.setActionCommand("Button 1");
    button.addActionListener( this );
    this.getContentPane().add( button );
    button = new JButton("Button 2");
    button.setActionCommand("Button 2");
    button.addActionListener( this );
    this.getContentPane().add( button, BorderLayout.EAST );
    public void actionPerformed(ActionEvent e)
              System.out.println(e.getActionCommand());
    popup.show( this, 0,0 );
    if( e.getActionCommand().equals( "Button 1" ) )
    popup.setSelected( menuItem1 );
    menuItem1.setArmed( true );
    menuItem2.setArmed( false );
    else if( e.getActionCommand().equals( "Button 2" ) )
    popup.setSelected( menuItem2 );
    menuItem1.setArmed( false );
    menuItem2.setArmed( true );

  • JRadioButton setSelected problem

    Hi,
    I am trying to change the status of my JRadio buttons to false, but they do not get updated. One of them still remains selected.
    Any ideas?
    radioButton1.setSelected(false);
    radioButton2.setSelected(false);

    devboris wrote:
    I am trying to change the status of my JRadio buttons to false, but they do not get updated. One of them still remains selected.
    Any ideas?
    radioButton1.setSelected(false);
    radioButton2.setSelected(false);
    This should be posted in the Swing forum, not the Java 2D forum.
    Regardless, if you are using Java 1.6, then I recommend that you call clearSelection on the ButtonGroup object. If you are not using Java 1.6, then you can always add to your button group another invisible jradiobutton and set its selected property to true.

Maybe you are looking for

  • I have Adobe Reader on my iPad. I cannot purchase a subscription.

    It's a 5th generation iPad,in excellent condition, but it hardly matters because I cannot purchase the same option on my new iPad Air. I  was able to purchase the first of the three options: Acrobat.com I  was able to purchase the second of the three

  • WM: Return Purchase order process issue-Using 161 movement type

    Hi       i did return PO with using 161 movementype .when i do GRN, WM is appear 601 movement type and storage type is 916 .       i  think is wrongly triggered the movementype and storage type 916 .       so where i made mistake the configuration.pl

  • Custom program to download texts from the Customer master

    Hi team, I want to create a Functional specification for downloading texts from the Customer master. Means we are trying to come up with a Zprogram development so that this program can be used later to download texts from the customer master. Can any

  • Blue screen on XP Pro X61

    Each time I unplug then replug FIOS into my X61, I always see blue screen of D followed by auto reboot.  There's never any problems afterward but I'm wondering: * is this indicative of a deeper problem? * why does this always occur on the unplug/repl

  • Transformer throws exception

    Hi I am working with Transformer to transform a xml file using a xsl. I get the following exception :- javax.xml.transform.TransformerConfigurationException: javax.xml.transform.Trans formerException: javax.xml.transform.TransformerException: stylesh