Disabled button getting focus

My problem is that a disabled button are getting focus, which is bad when the application are operated without a mouse.
I made this litlte demo to illustrate the problem.
Try pressing button no.1. This will disable button no.1 and button no.2,
but why are button no.2 getting focus afterwards?
* NewJFrame.java
* Created on 29. september 2005, 16:55
import javax.swing.*;
* @author  Peter
public class NewJFrame extends javax.swing.JFrame {
    /** Creates new form NewJFrame */
    public NewJFrame() {
        initComponents();
        printButtonStatus();
    private void printButtonStatus () {
        printFocus (jButton1);
        printFocus (jButton2);
        printFocus (jButton3);
        printFocus (jButton4);
     * Just debug inf.
    private void printFocus (JButton button) {
        System.out.println ("Button=<" + button.getText () + ">, Enabled=<" + button.isEnabled() + ">, Focus=<" + button.isFocusable() + ">");
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
        jPanel1.add(jButton1);
        jButton2.setText("jButton2");
        jPanel1.add(jButton2);
        jButton3.setText("jButton3");
        jPanel1.add(jButton3);
        getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
        jButton4.setText("jButton1");
        jPanel2.add(jButton4);
        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
        pack();
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:       
        jButton1.setEnabled(false);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        printButtonStatus();
     * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration
}

Very courius.
I have made a little change in your code.
1) scenario
Simply changing .setEnabled(false) invokation, the class works fine.
so
jButton2.setEnabled(false);
jButton3.setEnabled(false);
jButton1.setEnabled(false);
2) scenario
the class works fine also using your .setEnabled(false) order invokations and putting after those:
FocusManager.getCurrentManager().focusNextComponent();
I do not know exactly why, I suppose that is there something not properly
syncronized in events dispaching.
In my opinion:
a) setEnabled(false) at last calls for setEnabled(false) of JComponent
that fires a propertyChange event
so:
scenario 1)
buttons 2 and 3 are disabled before of button1 that has the focus in
that moment (given by a the mouse click on itself)
When botton1.setEnabled(false) is performed buttons 2 and 3 are
just disabled, so focus is got by button4 (that is enabled)
scenario 2)
button1 that has the focus (given it by the mouse click) becames
disabled before that button2 becames disabled too.
So, probably, when the event of PropertyChanged is fired and processed, button2.setEnabled(false) invokation has not been
just performed and swings looks for it as a focusable component
So, using FocusManager.getCurrentManager().focusNextComponent(),
we force the transer focus on next focusable component.
This is only a my suppose, looking what happens.
Regards.
import javax.swing.*;
* @author Peter
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
private void printButtonStatus () {
printFocus (jButton1);
printFocus (jButton2);
printFocus (jButton3);
printFocus (jButton4);
System.out.println("--------------------------------");
* Just debug inf.
private void printFocus (JButton button) {
System.out.println ("Button=<" + button.getText () + ">, Enabled=<" + button.isEnabled() + ">, Focus=<" + button.hasFocus() + ">, Focusable=<" + button.isFocusable() + ">");
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jButton4 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
jPanel1.add(jButton1);
jButton2.setText("jButton2");
jPanel1.add(jButton2);
jButton3.setText("jButton3");
jPanel1.add(jButton3);
getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
jButton4.setText("jButton1");
jPanel2.add(jButton4);
getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
pack();
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// I have simply change the order
jButton2.setEnabled(false);
jButton3.setEnabled(false);
jButton1.setEnabled(false);
// with this sentence the class work with original .setEnabled order
//FocusManager.getCurrentManager().focusNextComponent();
SwingUtilities.invokeLater(new Runnable()
public void run()
printButtonStatus();
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
// End of variables declaration
}

Similar Messages

  • Disabled Button Gets Focus in 1.4 and not in 1.3

    Hi
    I am in the process of migrating from version 1.3 to 1.4.2
    I have a screen on which I I have a button which is disabled when teh screen initializes. There are other items to which I can navigate through TAB.
    If i keep pressing Tab so that the focus comes to the disabled object, then it just stays there...nothing happens in version 1.4 although version 1.3 works for a similar scene and teh control goes to teh next component on the screen
    I have tried setting the focus by checking the status of teh button and have set it to the same value as being enabled or disabled.
    Any help please!
    Thanks
    priya

    hi
    I have tried this...but this doesnot seem to help...
    i have also set
    setRequestFocusEnabled(false)
    to disable mosue and keyboard events..but thsi doensot seem to help either...
    thanks
    priya

  • Disabled Object Gets Focus

    Hi
    I am in the process of migrating from version 1.3 to 1.4.2
    I have a screen on which I I have a button which is disabled when teh screen initializes. There are other items to which I can navigate through TAB.
    If i keep pressing Tab so that the focus comes to the disabled object, then it just stays there...nothing happens in version 1.4 although version 1.3 works for a similar scene and teh control goes to teh next component on the screen
    I have tried setting the focus by checking the status of teh button and have set it to the same value as being enabled or disabled.
    Any help please!
    Thanks
    priya

    If i keep pressing Tab so that the focus comes to the disabled object, then it just stays thereNever seen this behaviour.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Looking for a way to disable the "GET" button

    I have a user who would like to only allow the progressive streaming playback in iTunes U (ie disable the get button). I haven't seen any way to do this in the docs but it's entirely likely I'm missing some simple (or not) way to do this.

    You know, say after about, oh, six, seven beers I sometimes think, "Hey, I should write a book about iTunes U." It would be called something like "Deploying iTunes U" ... it wouldn't make any money (few tech books do) ... but it would win me loads of "wuv" (remember this is the beer talking). Then, of course, the next day rolls along and I realize how much work writing a book would actually be ... and then I think, "Crapspackle! ... how many beers did I have?"
    But if I were to write that iTunes U book, Chapter 1 would be called "About iTunes U" (every tech book has to start this way ... "About XML", "About MySQL", "About TCP/IP" ... like that) ... and the last section in that chapter would be called "What iTunes U is not". The first few paragraphs in that section would read this way ...
    iTunes U is not a streaming service. Sure, content displayed in iTunes U can be double-clicked and it will play ... in effect, content does stream. But while iTunes U can be made to stream content, you should not think of it as a generalized streaming service. The model for iTunes U is the iTunes Store. Think about why the iTunes Store succeeds. Podcasters do not stream ... people have been streaming since the mid-90s ... but podcasting took the world by storm. Why? Because content wasn't tethered to a network connection ... it became as portable as the iPod. This is the model you're buying into; this is the target you're aiming for.
    Whenever faculty at my site make "But ... !!" arguments, they pretty much run along one of the following lines:
    1. When I stream, students can't redistribute my content. I have control.
    Any reasonably determined person can capture a stream and redistribute it -- it is not technically "hard" to do. If a student wants to get your content onto an iPod or a PSP, he/she can easily do so. Do not fool yourself into thinking it can't happen. Chance are, it already has.
    2. I have copyrighted material in my content -- I can't afford for students to redistribute my content. I have to "know" that only students can get access to my content.
    See response to Argument 1. In addition, I have found that many instructors have naive notions about what copyright permits and forbids (and please do not be offended if you, dear reader, are an instructor ... copyright is really complicated, it's not your fault). From a copyright standpoint, streaming is basically irrelevant (you are not "protected" if you stream).
    At my university, we have a designated copyright authority. It is her job to know what's permitted and what's not for us. In any conversation with a faculty member about whether to stream or not, I always recast the question this way: "Are you allowed to use the material in a public way at all?" In every instance, I refer the questioning faculty member to our copyright expert for clarification.
    3. I want to make sure my students are sitting at desktop computer when they view my content. A stream forces them to do so.
    Not anymore. Think about how many phones have YouTube clients. Remember that these technologies are, for the most part, being driven by what students say they need. Students want to learn asynchronously -- that is, they want to listen to a summary of your lecture while commuting to campus; they want to listen to your supplementary materials while working out. A significant part of what makes iTunes U so cool and unique is that it exploits the synergy that exists between iTunes, the iTunes Store, and iPod music players. When you try to force students to view your material as a stream, you break this synergy. If you will not provide content the way students want to get it, they'll create their own solutions (see response to Argument 1).
    It can be tough to wrap your head around, but if you provide students with what they want, they won't circumvent your efforts. In effect, you will have the greater control. It requires a Zen way of thinking. If you focus on creating great content, and letting students get access to it asynchronously, you are taking away from the the major motivation for redistributing your work without permission.

  • Avoid window getting focus after pressing a mouse button on it

    I want that a window does not get focus although I press a mouse button on it, in Windows XP.
    I have search in Microsoft help and this fact is controlled by the Operating System itself. The notification that is sent after the user presses a mouse button is WM_MOUSEACTIVATE notification. The return value of this notification indicates the behaviour of the window after the mouse down, existing 4 options: MA_ACTIVATE, MA_ACTIVATEANDEAT; MA_NOACTIVATE & MA_NOACTIVATEANDEAT. The default is the first one, but I want to change the behaviour of the window to be the the third one: MA_NOACTIVATE, that does not activate the window, and does not discard the mouse message. The function that performs this is DefWindowProc according to the MSDN Help content.
    Any help about doing this in Labview? Is there any special function in Labview that allows setting this behaviour to a window or should I use a Windows dll? In that case how can be programmed? Has anyone done it before? I'm working with Labview 8.6.1, and I haven't found anything about this. Any help will be very useful.
    Thank you very much in advance.
    David Fernández

    It is the front panel window of a VI which I don't want to get focus. I have tried to achive this with property nodes, but the problem I think that cannot be solved in this way, because is the Operative System that gives the focus to the window when pressing a mouse button before Labview does anything. You can release the focus once the window have taken it with the Front Panel window focus property node, but what I really want is to keep the focus on the old window.
    My idea is that the VI act as a background of my application, so never can be over the rest of the windows. Some of them are floating but others are standard and I don't want to use modal windows, so I cannot solve this with the Window Appearance options.
    I have also tried to discard the mouse down in the Mouse Down? event, but I doesn't work, the window continues getting the focus although does not carry on any action.
    Any suggestion?
    Thank you for your interest
    David F

  • Workin in Live View when I press the zoom button to focus I get a white screen with a 5x or a 10x wr

    Working in Live View  When I press the zoom button to focus I get a white screen with a 5x or a 10x written.  I don't get the zoom picture.  It just started doing this today and I've been using it for years.  Any help?  Thank you.  OH   I have a 450D  (rebel xsi)
    Solved!
    Go to Solution.

    Which camera model?
    Also, what are your exposure settings? Canon DSLRs do exposure simulation in live-view. So if the settings would result in an over-exposure you might be cropping in to view an all white area.
    Tim Campbell
    5D II, 5D III, 60Da

  • How do I get the Manged bean and Taskflow logic for Disable button in User details Modify page

    Hi,
    I have a requirement where I have to add to custom buttons like "Terminate" and "Reinstate" in the users detail page. Terminate is closely modeled with "Disable" button of user details page. Before I develop the custom beans and register the task flow for the custom button, I just want to understand the logic written in the managed bean for "Disable" button and understand what is there in its associated task flow. Am trying to get these details from OIM. Not sure where exactly I can get the code for this and customize as per my requirement.
    Please suggest the exact location?
    Raghu

    Thanks for the information - I still was hoping that the article Mario mentioned above was accessible (perhaps just moved)?  Somewhere on the BC system?  Just so I can add it to my BC help folder - as well as even share it with clients who want to try things on their own (best to give them some help in that direction so they don't fumble through things).
    I have the checkout form populating information, if they have purchased in the past it will populate their address - but I am also trying to get their "account page" to do the same  (basically show them what their current information in the system is - then allow them to update whatever might be wrong or need changes).  We have a login page, for people to sign up without having "bought" something - so the CRM won't have their billing/shipping info in the system yet.  Trying to capture that without a purchasing being made.

  • I have tried all the methods in previous logs btu nothing works... how do i get my facebook id to work in settings on my ipad? there is no disable button in privacy only an app on my ipad

    ok so ive tried everything except for complete reset where i lose all my data and stuff... i reset my settings and i tried the privacy then facebook and disable there is no disable button... i am fedup i cant acces any of my games because its registered to that facebook which cannot log in please give me an answer that works because its really ******* me  off...

    Your backlight is out, it's a hardware problem and you'd be best served to take it in for an estimate. Or you could purchase an external display and use it as a desktop computer. You'll have to decide if repairing a 6 year old computer is worth it.

  • How setup browser laces import Bookmarks HTML security disable button open Device Manager security warni vewing mixed

    how to alter these settings?
    1.browser laces import Bookmarks HTML?
    2.security disable button open Device Manager?
    3.security warni vewing mixed?

    We didn't get a reply from you.  I just wanted to try and follow up before I close this out. 
    I'd like to know if the issue went away, and/or if you could confirm whether it's Firefox specific or happening in all browsers.

  • Disabling button Control.

    Hi all,
    i am creating custom add-on for Landed Cost screen, in that, i am placing a button say 'get cost'..
    now if i open landed cost in Find/Display mode, i want to disable that 'get cost' button.
    Can any body explain how to disable button in Find/Disable mode?
    in short,
    how to find whether the form i.e, landed cost is in Find Mode or Add Mode..?
    I appreciate your help...
    Thanks and Regards,
    KaviPrashu

    Hi,
    Try This............
    If pVal.FormType = "992" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_FORM_ACTIVATE And pVal.BeforeAction = False Then
                oform = sbo_application.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount)
                If oform.Mode = SAPbouiCOM.BoFormMode.fm_FIND_MODE Then
                    Dim oitm As SAPbouiCOM.Item
                    oitm = oform.Items.Item("get")
                    oitm.Enabled = False
                End If
            End If
    Thanks
    Shafi

  • Enable/disable buttons

    Hi All
    I have created an application wherein datablock is supposed to display 5 records at a time. In addition to it i have displayed 5 buttons alonside these records. But all the buttons are addresed by single name.
    I want to change the enable/disable property of the button in such a way that only those buttons get disabled where records value match with those given by me in procedure.
    Since all the buttons are having same name i am not able to target button corresponding to specific record.
    I will make the problem more clear:
    This is how my GUI looks
    Record1.element1 Record1.element2 Button1
    Record2.element1 Record2.element2 Button1
    Record3.element1 Record3.element2 Button1
    Record4.element1 Record4.element2 Button1
    Record5.element1 Record5.element2 Button1
    I want to disable button1 only corresponding to the record3.
    Can anyone help me out in this regard?

    Thanks Roel for your reply. I had already designed the way you mentioned(by using 1 button) but this is not the way application should look.
    Also I have to work on this application using designer only, that is the reason i have posted it in Designer forum so that i could get any clue as to how i have to proceed using designer.

  • Disable button

    as my previous post
    Loading
    external movie on top of all layers
    i am facing a problem now that all the buttons are still
    working when the external movie loads on top.
    I want all the menu buttons to be disabled when the external
    movie loads and there is a CLOSE Button in the external movie. i
    tried to search for how to disable the buttons. i found some, but
    couldnt understand what to do.
    So any help will be appreciated here plz.
    Thnx in advance.
    Regards

    hi,
    i did tried to put in the button code of my previous issue
    on (release) {
    // this.swapDepths(1);
    _root.createEmptyMovieClip("target_mc1",_root.getNextHighestDepth());
    _root.target_mc1._x = -600;
    _root.target_mc1._y = -150;
    _root.target_mc1.loadMovie("1.swf");
    security.enabled=false;
    i can't add any more buttons to disable them
    like after
    security btn
    if i add
    development btn
    only
    security btn
    will be disabled... all other btnz will be working.
    i want like, on click all the buttons gets disabled and in
    the external movie clip, when i click the CLOSE btn, all buttons
    gets enabled.
    i found the following code.
    for (var name in this) {
    if (typeof (this[name]) == "movieclip") {
    for (var name1 in this[name]) {
    if (typeof (this[name][name1]) == "object") {
    this[name][name1].enabled = false;
    but i don't know the right place to add this code. though it
    works fine.
    disables all the btns with the name. again i wud like to put
    the structure of my file:
    1. main container of left and rite menu, single layer
    2. 2 layers. down layer -> right menu. up layer ->
    left.
    Now if we enter in right menu mc....
    3. animation of right menu
    4. in animation mc there are 4 buttons animation tweening
    5. button container with actionScript on button
    6. Button
    any ideas plz?

  • Disabled button generates events

    Hello,
    I have a radio button that I want to disable while a background process is running.
    After the process finishes, I enable the button again.
    However, if the user clicks on the disabled button during the background process, an ActionEvent still gets generated.
    Then when the button is re-enabled, it responds to the event that was generated while it was disabled. I want to prevent my button from responding to events generated while it was disabled.
    I do not want to use the getGlassPane.setVisible(true) technique because I still want my cancel button to be able to generate events during the background process.
    I am using JDK 1.3.1 and my button is in a panel contained in a JFrame application.
    Suggestions?
    Thank you,
    Ted Hill

    Hello,
    I have a radio button that I want to disable while a background process is running.
    After the process finishes, I enable the button again.
    However, if the user clicks on the disabled button during the background process, an ActionEvent still gets generated.
    Then when the button is re-enabled, it responds to the event that was generated while it was disabled. I want to prevent my button from responding to events generated while it was disabled.
    I do not want to use the getGlassPane.setVisible(true) technique because I still want my cancel button to be able to generate events during the background process.
    I am using JDK 1.3.1 and my button is in a panel contained in a JFrame application.
    Suggestions?
    Thank you,
    Ted Hill

  • Disable button when user clicks

    Hi.,
    I am using jdev 11.1.5
    I need to disable button when user clicks the record which contain the value 'No'
    My scenario
    Id          Value
    1            Yes
    2            No
    3            YesThe button should get enabled for the first record which contain value 'Yes'
    In the above table the button should get enabled for
    Id        Value
    1          Yes          //while user clicks the record button must enabledfor 2 and 3 the button must be disabled
    could any one pls help me

    Hi,
    First get the selected value in bean and set it to String attribute,in your value change listener.
            public void customVLC(ValueChangeEvent valueChangeEvent) {
              //write code to get selected value
              this.selectedValue = "No";//Depend on your selected value on above
              AdfFacesContext.getCurrentInstance().addPartialTarget(getCbButton());//Bind button to bean and get UI here to refresh
       private String selectedValue;
        public void setSelectedValue(String selectedValue) {
            this.selectedValue = selectedValue;
        public String getSelectedValue() {
            return selectedValue;
        }in page put as
    disabled="#{YourBean.selectedValue eq 'No' ? true : false}"Here selectedValue keep the state for disable and enable the button
    I hope above information enough to resolve the issue..

  • JRootPane.setDefaultButton() only works after button got focus

    I try to set the default button on my JPanel (within a JInternalFrame) via getRootPane().setDefaultButton(), but this doesn't work. When I add the following FocusListener to the button, once the button got focus the first time, the button changes to the default button and stays the default button. So basically, the default button works, but only with the FocusListener code. Of course, that's not the solution i want to, because a defautl button should be the default without having to focus/select it.
                getRootPane().setDefaultButton(button);
                button.addFocusListener(new FocusAdapter() {
                    public void focusGained(FocusEvent e) {
                        JButton button = (JButton)e.getSource();
                        getRootPane().setDefaultButton(button);
                    public void focusLost(FocusEvent e) {
                        getRootPane().setDefaultButton(button);
                });Is there something else to do?

    The focus listeners are just to get the desired default button behaviour across L&Fs. They are not necessary to get any sort of default button behaviour as such. May be post some concise code that demonstrates the problem?

Maybe you are looking for

  • Unable To Install Oracle On P4 having Windows XP

    Hi, i m trying to install oracle 8 on p4 system with windows XP os. but every tiem i receive dthe message of "rdbms.map file not found while mapping" something like that. plz guide me how can i resolve this issue. bye

  • Logging the XML payload in Oracle Sales Cloud

    How can xml payloads for inbound and outbound web service call be logged in Oracle Sales Cloud? We need to capture the xml payloads as part of web service calls (inbound/outbound) and store it on server/objects. Is it possible to achieve this and if

  • How to add Logo in SAPSCRIPT

    Hi frnds, How I will upload Logo in SAPSCRIPT? I have created Header window, Now I want to add Logo in Header Window. Regards.

  • Mounting a dvd on Solaris 10

    I am a linux user, not a Solaris user and I am running solaris 10 on a Blade 100. I want to mount a dvd but am unsure of how to mount it because of the difference between Solaris and Linux command lines. "mount cdrom" does not work. I am sure this is

  • FP-DI-301: All channels went "HIGH" at the same time.

    Will FP-1001 "Watchdog" settings or FP-DI-301 module/channel settings cause digital inputs to go "High" regardless of the connected swithes positions? On 4/29/2009 @ 07:11:30 AM, while running a known good process, all of my FP-DI-301 input channels