Preventing A New Window From Grabbing Focus

I can't believe I couldn't find this in a FAQ, but I want to keep a JFramefrom grabbing focus when it is created and made visible.  I tried using:JFrame.setFocusable(false);before the window was made visible, but it didn't have any effect.  In thiscase, I have two progress windows, one monitoring the overall task andanother that opens up with each subtask and tracks that subtask.  I'venoticed that if I'm working in a text editor or word processor and I'mtyping when that 2nd window opens up, it grabs focus and if I type thewrong character, it triggers the "cancel" button.I'd like to just open this JFrame window without it grabbing focus.I know this is the opposite of the problem most people have and I'd thinkit'd be easy, but I can't find anything on this.Thanks!Hal
0
Hal
1/8/2008 7:45:27 AM
comp.lang.java.programmer 52297 articles. 0 followers. Post Follow

16 Replies
605 Views

Similar Articles

[PageSpeed] 49
On Tue, 08 Jan 2008 07:45:27 GMT, Hal Vaughan wrote:> I can't believe I couldn't find this in a FAQ, but I want to keep a> JFrame from grabbing focus when it is created and made visible. I> tried using:Your window manager or desktop environment can control this. You seemto be using KDE, which I'm told has focus-stealing settings thatactually work (unlike Gnome, or Windows)./gordon--
0
Gordon
1/8/2008 7:48:37 AM
Gordon Beaton wrote:> On Tue, 08 Jan 2008 07:45:27 GMT, Hal Vaughan wrote:>> I can't believe I couldn't find this in a FAQ, but I want to keep a>> JFrame from grabbing focus when it is created and made visible. I>> tried using:> > Your window manager or desktop environment can control this. You seem> to be using KDE, which I'm told has focus-stealing settings that> actually work (unlike Gnome, or Windows).The problem is I'm not the only one who will be using this program.  It'llbe used on Windows and other versions of Linux.Hal
0
Hal
1/8/2008 8:09:13 AM
On Jan 8, 3:09 am, Hal Vaughan <h...@halblog.com> wrote:> Gordon Beaton wrote:> > On Tue, 08 Jan 2008 07:45:27 GMT, Hal Vaughan wrote:> >> I can't believe I couldn't find this in a FAQ, but I want to keep a> >> JFrame from grabbing focus when it is created and made visible. I> >> tried using:>> > Your window manager or desktop environment can control this. You seem> > to be using KDE, which I'm told has focus-stealing settings that> > actually work (unlike Gnome, or Windows).>> The problem is I'm not the only one who will be using this program.  It'll> be used on Windows and other versions of Linux.>> HalI wish I could answer your question - I'm having a similar problem inwhich I open a new project and the JTree (which should have focus)does not (it belongs to the JFrame instead).I'll let you know if I figure anything out.
0
Jason
1/8/2008 2:04:52 PM
Hal Vaughan wrote:> I can't believe I couldn't find this in a FAQ, but I want to keep a JFrame> from grabbing focus when it is created and made visible.  I tried using:> > JFrame.setFocusable(false);> > before the window was made visible, but it didn't have any effect.  In thisAccording to this:<http://java.sun.com/javase/6/docs/api/java/awt/doc-files/FocusSpec.html#FocusableWindows>what you did should work.  You may wish to install a WindowListener or a WindowStateListener, and a VetoableChangeListner, as mentioned in the description, and see if you can do manually what they are saying there.   You might also make certain that your situation matches what they describe in the documentation link I provided.  Sometimes there can be subtle differences.Otherwise, I dunno.  Never actually tried this before.
0
Mark
1/8/2008 7:01:19 PM
Mark Space wrote:> Hal Vaughan wrote:>> I can't believe I couldn't find this in a FAQ, but I want to keep a >> JFrame>> from grabbing focus when it is created and made visible.  I tried using:>>>> JFrame.setFocusable(false);>>>> before the window was made visible, but it didn't have any effect.  In >> this> > According to this:> > <http://java.sun.com/javase/6/docs/api/java/awt/doc-files/FocusSpec.html#FocusableWindows> > > > what you did should work.  You may wish to install a WindowListener or a Oh wait, they've actually got a different method call in there:Window.setFocusableWindowState(false)is what you want.  My bad.
0
Mark
1/8/2008 7:03:01 PM
Mark Space wrote:> Mark Space wrote:>> Hal Vaughan wrote:>>> I can't believe I couldn't find this in a FAQ, but I want to keep a>>> JFrame>>> from grabbing focus when it is created and made visible.  I tried using:>>>>>> JFrame.setFocusable(false);>>>>>> before the window was made visible, but it didn't have any effect.  In>>> this>> >> According to this:>> >><http://java.sun.com/javase/6/docs/api/java/awt/doc-files/FocusSpec.html#FocusableWindows>>> >> >> what you did should work.  You may wish to install a WindowListener or a> > Oh wait, they've actually got a different method call in there:> > Window.setFocusableWindowState(false)> > is what you want.  My bad.Here's an interesting twist:I did Window.setFocusableWindowState(false), then after it was visible, didWindow.setFocusableWindowState(true).  It opened and didn't grab focus.  Sofar so good.  Then I ran my program, then pulled up a text editor.  Istarted my program and it was running through its queue.  Then I clicked onthe text editor and typed nothing but spaces, since I knew the space wouldactivate the cancel button on the pop up if it grabbed focus.  The windowsthat popped up *never* grabbed focus, but the space still activated thecancel button.I guess I'm going to have to go through a fair amount of reprogramming tokeep one window open and just reset it with each new sub-task, as well aschange the message in it.  This is one reason I get frustrated with Java. Sometimes you have to go around your thumb just to get to your elbow.Thanks for the info.  I guess the problem is more the way Java handlesthings than anything else.Hal
0
Hal
1/8/2008 9:05:13 PM
Hal Vaughan wrote:> I did Window.setFocusableWindowState(false), then after it was visible, did> Window.setFocusableWindowState(true).  It opened and didn't grab focus.  SoWhy did you setFocusableWindowState to true?  Won't a window receive events just fine if you don't have the focus?  Last time I checked it did.  Events are not the same as the focus in Swing.
0
Mark
1/8/2008 11:52:07 PM
Mark Space wrote:> Hal Vaughan wrote:> >> I did Window.setFocusableWindowState(false), then after it was >> visible, did>> Window.setFocusableWindowState(true).  It opened and didn't grab >> focus.  So> > Why did you setFocusableWindowState to true?  So he could blame Java for making him go around his thumb to reach his elbow?-- Lew
0
Lew
1/9/2008 2:35:17 AM
Mark Space wrote:> Hal Vaughan wrote:> >> I did Window.setFocusableWindowState(false), then after it was visible,>> did>> Window.setFocusableWindowState(true).  It opened and didn't grab focus. >> So> > Why did you setFocusableWindowState to true?  Won't a window receive> events just fine if you don't have the focus?  Last time I checked it> did.  Events are not the same as the focus in Swing.I tried it different ways.  There is a cancel button on it and the user mayneed to cancel the operation.  If the window can't get focus, the usercan't click the cancel button.Hal
0
Hal
1/9/2008 4:07:44 AM
Lew wrote:> Mark Space wrote:>> Hal Vaughan wrote:>> >>> I did Window.setFocusableWindowState(false), then after it was>>> visible, did>>> Window.setFocusableWindowState(true).  It opened and didn't grab>>> focus.  So>> >> Why did you setFocusableWindowState to true?> > So he could blame Java for making him go around his thumb to reach his> elbow?I just find if I have to do something in Perl, I can do it 5x faster than inJava.  Sometimes I feel like Java was made by the Spaceballs.  Remember thescene where Col. Saunders issues a lot of "Prepare for..." commandsfollowed by telling people to do what he just told them to prepare?  ThenDark Helmet says, "Why do you have to prepare for everything?  Why not justdo it?"  I feel like in Java I spend 2-3 lines preparing to do somethingthat takes one line.As for this particular case, if you can tell me how the user can click on acancel button (just a JButton) in a window that can't take focus AND havethat JButton call its ActionListener, I'm open to it, but I experimentedand had to have the window focusable for a JButton in it to receive aclick.Hal
0
Hal
1/9/2008 4:10:41 AM
Hal Vaughan wrote:> I tried it different ways.  There is a cancel button on it and the user may> need to cancel the operation.  If the window can't get focus, the user> can't click the cancel button.Huh, well in my test it didn't.  I'm on Windows though, so maybe other OSs work differently.  Can you try it on Windows?  I'm curious now if it's the code you have or a difference in OS.This quick and dirty, but it does it.  Quick and dirty in the generated by a GUI tool and I didn't clean it up.  Three files, three classes, snip on the <<<<<'s.package windowtest;public class Main {     /**      * @param args the command line arguments      */     public static void main(String[] args) {         // TODO code application logic here         MainFrame.main( args );     }}<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<package windowtest;public class MainFrame extends javax.swing.JFrame {     /** Creates new form MainFrame */     public MainFrame() {         initComponents();         setSize( 200, 200 );         setLocationRelativeTo( null );     }     /** 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.      */     // <editor-fold defaultstate="collapsed" desc="Generated Code">     private void initComponents() {         jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);         jButton1.setText("Make New Nonfocusable Frame");         jButton1.addActionListener(new java.awt.event.ActionListener() {             public void actionPerformed(java.awt.event.ActionEvent evt) {                 jButton1ActionPerformed(evt);             }         });         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());         getContentPane().setLayout(layout);         layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(layout.createSequentialGroup()                 .addGap(90, 90, 90)                 .addComponent(jButton1)                 .addContainerGap(97, Short.MAX_VALUE))         );         layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(layout.createSequentialGroup()                 .addGap(134, 134, 134)                 .addComponent(jButton1)                 .addContainerGap(141, Short.MAX_VALUE))         );         pack();     }// </editor-fold>     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {         // TODO add your handling code here:         new NFW().setVisible(true);     }     /**      * @param args the command line arguments      */     public static void main(String args[]) {         java.awt.EventQueue.invokeLater(new Runnable() {             public void run() {                 new MainFrame().setVisible(true);             }         });     }     // Variables declaration - do not modify     private javax.swing.JButton jButton1;     // End of variables declaration}<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<package windowtest;public class NFW extends javax.swing.JFrame {     /** Creates new form NFW */     public NFW() {         initComponents();         setSize( 200 , 200 );         setLocationRelativeTo( null );         setFocusableWindowState(false);     }     /** 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.      */     // <editor-fold defaultstate="collapsed" desc="Generated Code">     private void initComponents() {         jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);         jButton1.setText("Cancel");         jButton1.addActionListener(new java.awt.event.ActionListener() {             public void actionPerformed(java.awt.event.ActionEvent evt) {                 jButton1ActionPerformed(evt);             }         });         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());         getContentPane().setLayout(layout);         layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(layout.createSequentialGroup()                 .addGap(151, 151, 151)                 .addComponent(jButton1)                 .addContainerGap(178, Short.MAX_VALUE))         );         layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                 .addContainerGap(145, Short.MAX_VALUE)                 .addComponent(jButton1)                 .addGap(130, 130, 130))         );         pack();     }// </editor-fold>     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {         // TODO add your handling code here:         this.dispose();     }     /**      * @param args the command line arguments      */     public static void main(String args[]) {         java.awt.EventQueue.invokeLater(new Runnable() {             public void run() {                 new NFW().setVisible(true);             }         });     }     // Variables declaration - do not modify     private javax.swing.JButton jButton1;     // End of variables declaration}
0
Mark
1/9/2008 5:38:22 AM
Hal Vaughan wrote:> I can't believe I couldn't find this in a FAQ, but I want to keep a JFrame> from grabbing focus when it is created and made visible.  I tried using:> > JFrame.setFocusable(false);> > before the window was made visible, but it didn't have any effect.  In> this case, I have two progress windows, one monitoring the overall task> and> another that opens up with each subtask and tracks that subtask.  I've> noticed that if I'm working in a text editor or word processor and I'm> typing when that 2nd window opens up, it grabs focus and if I type the> wrong character, it triggers the "cancel" button.> > I'd like to just open this JFrame window without it grabbing focus.> > I know this is the opposite of the problem most people have and I'd think> it'd be easy, but I can't find anything on this.> > Thanks!> > HalI finally got a chance to get back to this issue.  I had time to think aboutit before I got back to it.  My first experience in working with Java was aprogram that had to work on Linux and Windows.  I had read how Java wasWORA, but I ran into troubles because I didn't realize a ChangeListenerwould pick up on a change that I created in a component and thought it onlypicked up on changes from the user.  On Linux (or was it Windows), thisproblem never showed up, but on the other OS, it was a mess.  Then Irealized the routines for rendering components must work differently oneach OS.  Since then, I've been suspicious of GUI issues that could changeon different platforms.After thinking about it, and looking at what other people said on thisthread, I decided I didn't want to spend a lot of time trying this ondifferent platforms and tweaking it.  While it was a pain, I basicallysolved this particular problem without dealing with the bigger picture.  Ichanged my own class that creates a simple window with a JProgressMonitorin it so it was possible to show status, in this case, a downloading file,then reset to the "Cylon" state with the animation that looks like a Cyloneye, then reset it again to start status for a task.  That way this monitorwindow stayed open throughout the entire queue, instead of closing aftereach data download then opening for the next one.Another point is that I didn't want to count on it opening and not grabbingfocus because there's always a chance, with a new version of Windows or KDEor X Windows, that it might not work quite the same, so I just wanted toavoid that entire questions.In some ways I took the easy way out.  It involved more recoding than Iwanted to do, but only about 45 minutes worth.Thanks for all the help.  I did learn a few things that I'll be playing within the future.  In this case, I guess I just chickened out and did what Iknew I could get working quickly.Hal
0
Hal
1/19/2008 11:14:20 PM
Mark Space wrote:

> Hal Vaughan wrote:
> 
>> I tried it different ways.  There is a cancel button on it and the user
>> may
>> need to cancel the operation.  If the window can't get focus, the user
>> can't click the cancel button.
> 
> Huh, well in my test it didn't.  I'm on Windows though, so maybe other
> OSs work differently.  Can you try it on Windows?  I'm curious now if
> it's the code you have or a difference in OS.
> 
> This quick and dirty, but it does it.  Quick and dirty in the generated
> by a GUI tool and I didn't clean it up.  Three files, three classes,
> snip on the <<<<<'s.

I had tried this quickly earlier and got a lot of errors and had to get my
work done, so I set it aside.  I just got back to it to look it over and
now I see the error is that I have Java5 on my system for testing but my
environment set in Eclipse for 1.4.2 so I don't deal with issues with
clients who haven't upgraded.  You're using GroupLayout, which Java didn't
put in until Java6.  I'm going to have to d/l Java6 and put it in a
separate directory so it doesn't interfere with my other settings.  I'll do
that over the weekend and see how it works.

I just found another issue that seems to be different on Windows vs. Linux,
but I haven't been able to follow up on it yet.  I have a program a friend
was testing that uses a JList on a JScrollPane.  On Linux I've had no
trouble with it scrolling when I refresh, but on his XP system it seems
that every time I refresh the list, it scrolls to the top.

Hal

> 
> package windowtest;
> 
> public class Main {
> 
>      /**
>       * @param args the command line arguments
>       */
>      public static void main(String[] args) {
>          // TODO code application logic here
>          MainFrame.main( args );
>      }
> 
> }
> 
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> 
> package windowtest;
> 
> public class MainFrame extends javax.swing.JFrame {
> 
>      /** Creates new form MainFrame */
>      public MainFrame() {
>          initComponents();
>          setSize( 200, 200 );
>          setLocationRelativeTo( null );
>      }
> 
>      /** 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.
>       */
>      // <editor-fold defaultstate="collapsed" desc="Generated Code">
>      private void initComponents() {
> 
>          jButton1 = new javax.swing.JButton();
> 
>  
> setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
> 
>          jButton1.setText("Make New Nonfocusable Frame");
>          jButton1.addActionListener(new java.awt.event.ActionListener() {
>              public void actionPerformed(java.awt.event.ActionEvent evt) {
>                  jButton1ActionPerformed(evt);
>              }
>          });
> 
>          javax.swing.GroupLayout layout = new
> javax.swing.GroupLayout(getContentPane());
>          getContentPane().setLayout(layout);
>          layout.setHorizontalGroup(
>  
> layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(90, 90, 90)
>                  .addComponent(jButton1)
>                  .addContainerGap(97, Short.MAX_VALUE))
>          );
>          layout.setVerticalGroup(
>  
> layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(134, 134, 134)
>                  .addComponent(jButton1)
>                  .addContainerGap(141, Short.MAX_VALUE))
>          );
> 
>          pack();
>      }// </editor-fold>
> 
>      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
>      {
>          // TODO add your handling code here:
>          new NFW().setVisible(true);
>      }
> 
>      /**
>       * @param args the command line arguments
>       */
>      public static void main(String args[]) {
>          java.awt.EventQueue.invokeLater(new Runnable() {
>              public void run() {
>                  new MainFrame().setVisible(true);
>              }
>          });
>      }
> 
>      // Variables declaration - do not modify
>      private javax.swing.JButton jButton1;
>      // End of variables declaration
> 
> }
> 
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> 
> 
> package windowtest;
> 
> 
> public class NFW extends javax.swing.JFrame {
> 
>      /** Creates new form NFW */
>      public NFW() {
>          initComponents();
>          setSize( 200 , 200 );
>          setLocationRelativeTo( null );
>          setFocusableWindowState(false);
>      }
> 
>      /** 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.
>       */
>      // <editor-fold defaultstate="collapsed" desc="Generated Code">
>      private void initComponents() {
> 
>          jButton1 = new javax.swing.JButton();
> 
>  
> setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
> 
>          jButton1.setText("Cancel");
>          jButton1.addActionListener(new java.awt.event.ActionListener() {
>              public void actionPerformed(java.awt.event.ActionEvent evt) {
>                  jButton1ActionPerformed(evt);
>              }
>          });
> 
>          javax.swing.GroupLayout layout = new
> javax.swing.GroupLayout(getContentPane());
>          getContentPane().setLayout(layout);
>          layout.setHorizontalGroup(
>  
> layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(layout.createSequentialGroup()
>                  .addGap(151, 151, 151)
>                  .addComponent(jButton1)
>                  .addContainerGap(178, Short.MAX_VALUE))
>          );
>          layout.setVerticalGroup(
>  
> layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
>              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
> layout.createSequentialGroup()
>                  .addContainerGap(145, Short.MAX_VALUE)
>                  .addComponent(jButton1)
>                  .addGap(130, 130, 130))
>          );
> 
>          pack();
>      }// </editor-fold>
> 
>      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
>      {
>          // TODO add your handling code here:
>          this.dispose();
>      }
> 
>      /**
>       * @param args the command line arguments
>       */
>      public static void main(String args[]) {
>          java.awt.EventQueue.invokeLater(new Runnable() {
>              public void run() {
>                  new NFW().setVisible(true);
>              }
>          });
>      }
> 
>      // Variables declaration - do not modify
>      private javax.swing.JButton jButton1;
>      // End of variables declaration
> 
> }

0
hal (27)
1/25/2008 10:36:57 PM
Mark Space wrote:> Hal Vaughan wrote:> >> I tried it different ways.  There is a cancel button on it and the user>> may>> need to cancel the operation.  If the window can't get focus, the user>> can't click the cancel button.> > Huh, well in my test it didn't.  I'm on Windows though, so maybe other> OSs work differently.  Can you try it on Windows?  I'm curious now if> it's the code you have or a difference in OS.> > This quick and dirty, but it does it.  Quick and dirty in the generated> by a GUI tool and I didn't clean it up.  Three files, three classes,> snip on the <<<<<'s.I had time to download Java6 and try this earlier than I expected.  It doeswork fine on Linux.  I added in a Thread.sleep() statement so I could clickthe button, then start typing so I could watch and see if I lost anycharacters when the window opened or if I were hitting the space key overand over, if it would trigger the "Cancel" button and it didn't.So I'd say this works on Linux.  I could swear I used the same method tomake a window non-focusable, but when I did, it was not possible to pressthe "Cancel" button.  I've trashed my code that wasn't working and, like Isaid, gone with a different idea.  However, I'll be looking over your codeto see if you did anything differently than I did.It could also be a bug or glitch that was fixed between Java5 and Java6.Thanks for the help on this and I'm glad I finally got time to compile andtest this for you.Hal> package windowtest;> > public class Main {> >      /**>       * @param args the command line arguments>       */>      public static void main(String[] args) {>          // TODO code application logic here>          MainFrame.main( args );>      }> > }> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<> > package windowtest;> > public class MainFrame extends javax.swing.JFrame {> >      /** Creates new form MainFrame */>      public MainFrame() {>          initComponents();>          setSize( 200, 200 );>          setLocationRelativeTo( null );>      }> >      /** 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.>       */>      // <editor-fold defaultstate="collapsed" desc="Generated Code">>      private void initComponents() {> >          jButton1 = new javax.swing.JButton();> >  > setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);> >          jButton1.setText("Make New Nonfocusable Frame");>          jButton1.addActionListener(new java.awt.event.ActionListener() {>              public void actionPerformed(java.awt.event.ActionEvent evt) {>                  jButton1ActionPerformed(evt);>              }>          });> >          javax.swing.GroupLayout layout = new> javax.swing.GroupLayout(getContentPane());>          getContentPane().setLayout(layout);>          layout.setHorizontalGroup(>  > layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)>              .addGroup(layout.createSequentialGroup()>                  .addGap(90, 90, 90)>                  .addComponent(jButton1)>                  .addContainerGap(97, Short.MAX_VALUE))>          );>          layout.setVerticalGroup(>  > layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)>              .addGroup(layout.createSequentialGroup()>                  .addGap(134, 134, 134)>                  .addComponent(jButton1)>                  .addContainerGap(141, Short.MAX_VALUE))>          );> >          pack();>      }// </editor-fold>> >      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)>      {>          // TODO add your handling code here:>          new NFW().setVisible(true);>      }> >      /**>       * @param args the command line arguments>       */>      public static void main(String args[]) {>          java.awt.EventQueue.invokeLater(new Runnable() {>              public void run() {>                  new MainFrame().setVisible(true);>              }>          });>      }> >      // Variables declaration - do not modify>      private javax.swing.JButton jButton1;>      // End of variables declaration> > }> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<> > > package windowtest;> > > public class NFW extends javax.swing.JFrame {> >      /** Creates new form NFW */>      public NFW() {>          initComponents();>          setSize( 200 , 200 );>          setLocationRelativeTo( null );>          setFocusableWindowState(false);>      }> >      /** 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.>       */>      // <editor-fold defaultstate="collapsed" desc="Generated Code">>      private void initComponents() {> >          jButton1 = new javax.swing.JButton();> >  > setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);> >          jButton1.setText("Cancel");>          jButton1.addActionListener(new java.awt.event.ActionListener() {>              public void actionPerformed(java.awt.event.ActionEvent evt) {>                  jButton1ActionPerformed(evt);>              }>          });> >          javax.swing.GroupLayout layout = new> javax.swing.GroupLayout(getContentPane());>          getContentPane().setLayout(layout);>          layout.setHorizontalGroup(>  > layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)>              .addGroup(layout.createSequentialGroup()>                  .addGap(151, 151, 151)>                  .addComponent(jButton1)>                  .addContainerGap(178, Short.MAX_VALUE))>          );>          layout.setVerticalGroup(>  > layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)>              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,> layout.createSequentialGroup()>                  .addContainerGap(145, Short.MAX_VALUE)>                  .addComponent(jButton1)>                  .addGap(130, 130, 130))>          );> >          pack();>      }// </editor-fold>> >      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)>      {>          // TODO add your handling code here:>          this.dispose();>      }> >      /**>       * @param args the command line arguments>       */>      public static void main(String args[]) {>          java.awt.EventQueue.invokeLater(new Runnable() {>              public void run() {>                  new NFW().setVisible(true);>              }>          });>      }> >      // Variables declaration - do not modify>      private javax.swing.JButton jButton1;>      // End of variables declaration> > }
0
Hal
1/26/2008 12:33:55 AM
Hal Vaughan wrote:> Mark Space wrote:> So I'd say this works on Linux.  I could swear I used the same method to> It could also be a bug or glitch that was fixed between Java5 and Java6.> Well thanks for the report.  At least is seems to work ok with Java 6.Last time I worked on something like this (getting one component to hold the focus and insert caret, all the time) I came up with all kinds of crazy schemes to make it work.  I made my own listeners for the FocusManager (I think that's it) and all sorts of stuff before I realized there was an easy way to do it (just set all the components in the window to non-focusable ("setFocusable(false)") except the one I wanted).  I had to back out all kinds of stuff, so I'm guessing you had some little issue in the way you were setting up your windows that might have been left over from other experiments.Incidentally, the GroupLayout is totally incidental to the program.  It should work regardless what layout manager you use.  If I had hand coded it to clean it up, I probably would have just used the default BorderLayout and FlowLayout.The important bits are:In the main window, set it up like this:>>      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)>>      {>>          // TODO add your handling code here:>>          new NFW().setVisible(true);>>      }That's it.  I use the main window to hold a button that makes new NFW ("non-focusable window").  You could use any GUI builder and layout manager to set up that button.And in the NFW, I just:>> public class NFW extends javax.swing.JFrame {>>>>      /** Creates new form NFW */>>      public NFW() {>>          initComponents();//... snip>>          setFocusableWindowState(false);>>      }That's it.  setFocusableWindowState(false), the rest is just boilerplate set up.  The button in the NFW window has is just to make sure it can receive clicks, and disposes the window.Again, any layout and any GUI builder would work.  Bog standard Java and boilerplate.
0
Mark
1/26/2008 5:29:56 AM
Mark Space wrote:> Hal Vaughan wrote:>> Mark Space wrote:> >> So I'd say this works on Linux.  I could swear I used the same method to> >> It could also be a bug or glitch that was fixed between Java5 and Java6.>> > > Well thanks for the report.  At least is seems to work ok with Java 6.> > Last time I worked on something like this (getting one component to hold> the focus and insert caret, all the time) I came up with all kinds of> crazy schemes to make it work.  I made my own listeners for the> FocusManager (I think that's it) and all sorts of stuff before I> realized there was an easy way to do it (just set all the components in> the window to non-focusable ("setFocusable(false)") except the one I> wanted).  I had to back out all kinds of stuff, so I'm guessing you had> some little issue in the way you were setting up your windows that might> have been left over from other experiments.> > Incidentally, the GroupLayout is totally incidental to the program.  It> should work regardless what layout manager you use.  If I had hand coded> it to clean it up, I probably would have just used the default> BorderLayout and FlowLayout.> > The important bits are:> > In the main window, set it up like this:> > >>>      private void jButton1ActionPerformed(java.awt.event.ActionEvent>>>      evt)>>>      {>>>          // TODO add your handling code here:>>>          new NFW().setVisible(true);>>>      }That's where I added a sleep() statement to delay it.  I stalled itsomething like 5 seconds so I could click the button, then switch to mytext editor.  The first time I just typed and kept my focus on the texteditor until I realized the window had already opened, then scanned what Ihad typed and there were no missing characters.  The next few times I justkept tapping the space bar since I've seen that trigger JButtons and therewas no indication it effected the window at all.> That's it.  I use the main window to hold a button that makes new NFW> ("non-focusable window").  You could use any GUI builder and layout> manager to set up that button.> > And in the NFW, I just:> >>> public class NFW extends javax.swing.JFrame {>>>>>>      /** Creates new form NFW */>>>      public NFW() {>>>          initComponents();> //... snip>>>          setFocusableWindowState(false);>>>      }> > > That's it.  setFocusableWindowState(false), the rest is just boilerplate> set up.  The button in the NFW window has is just to make sure it can> receive clicks, and disposes the window.I tried to set the focusable state, but maybe I did, as you said, have otherstuff from other experiments in the way.  At least now we know your way issimple and works!Hal
0
Hal
1/26/2008 9:37:45 PM
Reply:
Similar Artilces:

NEW GAME: Bozxle (remake of Boxxle)
Here is a remake of Boxxle, http://www.worldofspectrum.org/forums/showthread.php?t=36151 On Mon, 10 Oct 2011 15:27:06 +0100, Polomint <polomint@gmail.com> wrote: > Here is a remake of Boxxle, Really nice. The only little quirk I noticed is that you have to push against any box one extra time for it to "notice" that you have completed the level -- is that intentional? Eq. ...

New to Python
Please reply both here and directly to my email address relee_s@hotmail.com I just found out about Python today and it sounds very interesting, but I'm having trouble finding solid information about my main question. Is Python a compiled language, or merely a sequence of commands fed into a seperate program? The impression I get from www.python.org is that it is a compiled very high level language, which is extendable via C++. I'm a C++ programmer and the tools and utilities referred to existing in Python would increase the development time of my projects. However, what I'...

Analogue of Windows I/O completion ports on Linux?
Hi, I'm looking for advice on how I can port to Linux a high-perf Windows app using I/O completion ports for network communication. The model I'm looking for is multiple UDP sockets attached to a single port that I can wait on with timeout. This allows me to limit to a single thread polling on the completion port, managing its own timer and scheduling, and processing events sequentially. Is there some way to achieve this without hacking in the kernel? Any recent or planned kernel additions or extensions that somebody would be aware of? I'm well aware of the option to g...

Prevent ssh-User from login
Hi together suppose I have a teamuser (say: ppcenter). Because of new SOA/SOX we need now personalized users for login to our servers, where the users must do a su to this teamuser. How can I prevent in the future this teamuser from direct login to the servers. No one should be able to login to a machine with this teamuser. THX Friedhelm On 2007-04-29, Friedhelm Neyer <Friedhelm.Neyer@t-online.de> wrote: > suppose I have a teamuser (say: ppcenter). Because of new SOA/SOX we > need now personalized users for login to our servers, where the users > must do a su to this ...

Brand new Apple DVI-VGA adapter cable $5 on eBay
Hi All, Last night I listed a brand new Apple DVI to VGA adapter cable on eBay starting at only $5 with no reserve. It's still sealed in the package. I bought it with my new G5 from MacMall and found out they included one, so I don't need 2 of them. You can use this to connect an existing VGA monitor to any newer Mac (or PC) that has a DVI video connector. I used the other cable to connect my old Apple 20-inch Multisync to the G5. Made it cheaper to upgrade since I didn't have to buy a new LCD screen with it. The Apple part number is M8754G/A, and MacMall currently ...

window.onload when DOM complete
There has been a bit of work done to get an init() function to run when the DOM is complete but before all the images have been downloaded. The idea is to kickoff init() scripts when all the elements are there but not wait for large images. Below is a script which uses 3 different techniques, one each for IE, Safari and Mozill/Opera 9. The Safari version uses browser sniffing, but I think with a little work that could be removed - the following code is really just a proof of concept. My simple solution is to insert a script element that calls the init function just before the closin...

Two new Tiller games
France 1914 - WWI, battalion level operational, first in a series ... Panzer campaigns style. http://www.hpssims.com/Pages/products/WW1/France14/france14.html Red Victory - Eastern front 43-45, tactical ... Squad Battles Advance of the Reich sequel. http://www.hpssims.com/Pages/products/SB/RedVictory/redvictory.html Regards, Mike Kreuzer www.mikekreuzer.com "Mike Kreuzer" <mike@FIRSTNAMEkreuzer.com> wrote in message news:4c396def$1@dnews.tpgi.com.au... > France 1914 - WWI, battalion level operational, first in a series ... > Panzer campaigns styl...

Wannna talk to me now ?? I love making new friends...
hi friend, Do you love chatting ?? using any messenger ?? It's Time for a change now.. Switch to Skype Now !! www.tigerzclub.com/skype.htm Take Care ... My Skype Id : sweetgirl69 See You there.... ...

Creative Technologist Connor Raus Brings New BOWIE Biography Into the Limelight
BOWIE, a new biography by noted author and rock 'n' roll journalist Marc Spitz was released on October 27th, 2009 by Crown/Random House. Connor Raus, the marketer behind the book's online success has just released a case study which details the digital marketing strategy. When author Marc Spitz needed to draw attention to his new book =E2=80=9CBOWIE: A Biography,=E2=80=9D he knew what his publisher could and = couldn=E2=80=99t do. That=E2=80=99s why Spitz turned to new media expert Connor Raus. =E2=80=9CPublishers specialize in drawing broad attention through tradition=...

[News] Another New Review of the Linux-based Eee PC, Linux Migrations with Eee
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Asus Eee PC 900 Laptop ,----[ Quote ] | Upon its release last fall, the Asus Eee PC 4G was a diminutive sight to | behold: Sure, the tiny Linux-based system demanded some sacrifices, but we | were still buying what this budget ultraportable was selling, presumably to | cash-strapped shoppers and travelers who wanted a cheap second notebook for | the road. `---- http://computershopper.com/reviews/asus-eee-pc-900-laptop-review Linux after one year ,----[ Quote ] | I have some friends who now run Linux on their desktops and have purchased...

Toplevel.pm
Hi, Anyone know the stability of the code in Toplevel.pm listed after __END__? There is a section of this module which contains useful looking code for configuring 'Focus Group'; in particular sub FG_Out is of interest. Any info would be appreciated. Thanks, Jason ...

Prevent attachments?
Hi I would like to prevent attachment goinf to attachment folder. I would like to deside which are going there. Is this possible. Now they go there when I open the mail. Thanks Kalevi Kalevi wrote: >Hi >I would like to prevent attachment goinf to attachment folder. I would like >to deside which are going there. Is this possible. Now they go there when I >open the mail. > > > > Actually, they go there when the mail is downloaded. You can specify where they go, but you can't change that on the fly. Get a copy util that will copy or move fr...

Can't find VI on windows startup
HI, &nbsp; I have a shortcut on my desktop that we use to run a&nbsp;NI-motion &amp; NI-vision application (in the development environment). If I reboot the PC and try to run the application from this shortcut ASAP, windows (I think)&nbsp;reports that the VI does not exist and suggests searching for it. Then it loads, sometimes with a broken run arrow. Closing the&nbsp;VI and reloading it&nbsp;fixes the problem, and from that point onwards the problem goes away. I notice if I wait a while before clicking the shortcut after a re-boot all is OK. I think I saw a question o...

ODBC and D3 Window
I am a newbie in Pick. I am ask to setup an ODBC link to a Pick application developed by an ex-staff. No documentation available. I downloaded the ODBC client software from Raining Data. While setting up the ODBC, I come across a few items that are new to me. My questions: 1. How do I find out the Virtual Machine name? 2. How do I find out the Server version? I think my version is 7.2x 3. In Pick, what is the name or file extension of the datafile? In Access is .MDB and for FoxPro is .DBF Thank you very much Christine -- Posted via http://dbforums...

Preventing wrap searches
I thought I had something set to prevent emacs from wrapping when it hits the end of file during a search, but emacs doesn't seem to be behaving like that now and nothing in .emacs looks like it performs this. So, is there a setting that will prevent emacs from doing wrapping in searches and if so, what is it? CMM Hi Charles, * Charles M <CharlesM@10.sub-75-205-32.myvzw.com> wrote: > So, is there a setting that will prevent emacs from doing wrapping in > searches and if so, what is it? That seems to work, switches wrapping off: (setq isearch-wrap-function '(lambda ...

DVD-Ram driver for Windows
My OS: Windows XP pro SP2 I've just bought and installed a pioneer DVR-109 DVD writer and I'm finding it a bit hard to swallow that this drive will read DVD-Ram but not write to it. I'm a big fan of DVD-Ram, I really like it as a convenient re-useable storage medium. Problem is, it's hard to find DVD-Ram supported drives, manufacturers seem to steer clear of them. Anyway, I was wondering if anyone knew of a downloadable driver that would enable this drive to write to DVD-Ram. I've already tried one driver - the BHA driver (which I have on CD) but it made no di...

Nobody is the new pivot boy.
Looks like 'Nobody' has pushed out Creepy Chris from the top spot as COLA's pivot boy. Nobody is a perfect nym for that loser. Go get em' pivot boy! On 07/07/2012 01:59 PM, bimmer wrote: > Looks like 'Nobody' has pushed out Creepy Chris from the top spot as > COLA's pivot boy. > Nobody is a perfect nym for that loser. > Go get em' pivot boy! The astroturfers have made me their new target. I must be doing good. On 7/7/2012 3:03 PM, Nobody wrote: > On 07/07/2012 01:59 PM, bimmer wrote: >> Looks like 'Nobody' has pu...

Problem in Unit Testing Methods that start new threads
I have a bit of doubt, in Unit Testing Programs that start new threads. Please have a look at the code below: class Foobar def hello_world p "Hello World" @thread_status = false end def new_thread_start Thread.new do sleep(100) @thread_status = true end end end # here goes the lame test case require "test/unit" module Test::Unit::Assertions def assert_false(t_object,message=nil) boolean = !t_object full_message = build_message(message,'<?> Object is not false',boolean) assert_block(full_message) { boolea...

add window.status javascript to a:hover css pseudo-class?
Hi, basically what I'd like to do is suppress the action that causes the URL to show up in the browser status bar when I roll over a hyperlink. I know I could use the onmouseover event in each anchor tag, but I'd rather be able to do it globally thru my stylesheet, rather than having to futz with each link. Does anyone know a solution for this? It seems like you could maybe add quick window.status='blah' javascript or something to the a:hover pseudoclass to control status bar behavior. Thanks. Bob P. wrote: > Hi, basically what I'd like to do is suppress the action ...

[News] [Rival] Windows Vista So Bad It Going to be Banned
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Texas senator wants to ban Vista purchases ,----[ Quote ] | Windows Vista gets a lot of grief both in tech circles and the general public | — but one Texas lawmaker wants to make it a matter of public policy. `---- http://www.theregister.co.uk/2009/04/01/texas_senator_wants_state_gov_ban_on_vista/ Texas Bans Vista For State Gov http://consumerist.com/5194331/texas-bans-vista-for-state-gov Texas senator: Let's ban Windows Vista purchases http://news.cnet.com/8301-13846_3-10209557-62.html President of Bluehost.com: Steve Ballmer is ...

V6 UNIX (Thompson) Shell new page
The Version 6 UNIX Thompson Shell project now has a new homepage graciously hosted on the SDF Public Access UNIX System. Sources, documentation and information are all available for download at: http://v6shell.org Enjoy! On Jan 17, 4:31=A0pm, marti...@sdf.lNoOnSePsAtMar.org (SDF Poster) wrote: > The Version 6 UNIX Thompson Shell project now has a new homepage > graciously hosted on the SDF Public Access UNIX System. =A0Sources, > documentation and information are all available for download at: > > http://v6shell.org > > Enjoy! Thanks! =3DBrian ...

A new reader? Welcome to comp.os.linux.misc, read this first if you're new here (FAQ) #373
Netiquette 2007-07#3 New reader? Great! Welcome! Here's how to make best use of this newsgroup and get yourself a slice of the best help available. Now read on ... TESTING YOUR CONNECTION Errm, first a delicate point. Often users accessing a forum like this for the first time don't realize that posts don't show up immediately, certainly not for several minutes, and maybe not for some hours. In the old days, it took as long as the camel bearing the news took! So they tend to post "test" messages. Plea...

prevent Matlab from using its own libs
Hi, i have compiled a mex program using libhdf5 in version 1.8.5 as a shared library. Using -Wl,-rpath... i get ldd to find the correct libs also if executed inside matlab using !. running the mex program it stops telling me that the headers version 1.8.5 conflicts with the libhdf5 version 1.8.3. Hence it uses the libhdf5 delivered with matlab and not the one used to build the program. Also setting LD_LIBRARY_PATH to setenv('LD_LIBRARY_PATH', [ '/first/path/of/my/libs:' getenv('LD_LIBRARY_PATH') ] ) inside matlab does not help. Again !ldd gives the correct l...

[News] GNU/Linux User Meets Windows on the Deskto
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Primal Scream! ,----[ Quote ] | AAAGGGHHHHHH!!! I let that other OS do it to me | again. Yesterday I was giving my second lecture | for my computer science course. I was using an | XP machine on a cart as a terminal via RDP to | my GNU/Linux terminal server. | | I started up Impressive with a PDF slide show | and some images to finish it off. I had set | Impressive to show my progress bar for 20 | minutes side to side. I had just got into it | when a pop-up from the underlying OS | intervened. It warned me that it would re-re- | reboot ...

A new reader? Welcome to comp.os.linux.misc, read this first if you're new here (FAQ) #245
Netiquette 2006-04#1 New reader? Great! Welcome! Here's how to make best use of this newsgroup and get yourself a slice of the best help available. Now read on ... TESTING YOUR CONNECTION Errm, first a delicate point. Often users accessing a forum like this for the first time don't realize that posts don't show up immediately, certainly not for several minutes, and maybe not for some hours. In the old days, it took as long as the camel bearing the news took! So they tend to post "test" messages. Plea...