Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Preventing A New Window From Grabbing Focus

Reply
Thread Tools

Preventing A New Window From Grabbing Focus

 
 
Hal Vaughan
Guest
Posts: n/a
 
      01-09-2008
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 in
Java. Sometimes I feel like Java was made by the Spaceballs. Remember the
scene where Col. Saunders issues a lot of "Prepare for..." commands
followed by telling people to do what he just told them to prepare? Then
Dark Helmet says, "Why do you have to prepare for everything? Why not just
do it?" I feel like in Java I spend 2-3 lines preparing to do something
that takes one line.

As for this particular case, if you can tell me how the user can click on a
cancel button (just a JButton) in a window that can't take focus AND have
that JButton call its ActionListener, I'm open to it, but I experimented
and had to have the window focusable for a JButton in it to receive a
click.

Hal
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      01-09-2008
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.WindowConstan ts.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.WindowConstan ts.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.TRAILI NG,
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

}



 
Reply With Quote
 
 
 
 
Hal Vaughan
Guest
Posts: n/a
 
      01-19-2008
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!
>
> Hal


I finally got a chance to get back to this issue. I had time to think about
it before I got back to it. My first experience in working with Java was a
program that had to work on Linux and Windows. I had read how Java was
WORA, but I ran into troubles because I didn't realize a ChangeListener
would pick up on a change that I created in a component and thought it only
picked up on changes from the user. On Linux (or was it Windows), this
problem never showed up, but on the other OS, it was a mess. Then I
realized the routines for rendering components must work differently on
each OS. Since then, I've been suspicious of GUI issues that could change
on different platforms.

After thinking about it, and looking at what other people said on this
thread, I decided I didn't want to spend a lot of time trying this on
different platforms and tweaking it. While it was a pain, I basically
solved this particular problem without dealing with the bigger picture. I
changed my own class that creates a simple window with a JProgressMonitor
in 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 Cylon
eye, then reset it again to start status for a task. That way this monitor
window stayed open throughout the entire queue, instead of closing after
each data download then opening for the next one.

Another point is that I didn't want to count on it opening and not grabbing
focus because there's always a chance, with a new version of Windows or KDE
or X Windows, that it might not work quite the same, so I just wanted to
avoid that entire questions.

In some ways I took the easy way out. It involved more recoding than I
wanted to do, but only about 45 minutes worth.

Thanks for all the help. I did learn a few things that I'll be playing with
in the future. In this case, I guess I just chickened out and did what I
knew I could get working quickly.

Hal
 
Reply With Quote
 
Hal Vaughan
Guest
Posts: n/a
 
      01-25-2008
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.WindowConstan ts.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.WindowConstan ts.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.TRAILI NG,
> 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
>
> }


 
Reply With Quote
 
Hal Vaughan
Guest
Posts: n/a
 
      01-26-2008
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 does
work fine on Linux. I added in a Thread.sleep() statement so I could click
the button, then start typing so I could watch and see if I lost any
characters when the window opened or if I were hitting the space key over
and 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 to
make a window non-focusable, but when I did, it was not possible to press
the "Cancel" button. I've trashed my code that wasn't working and, like I
said, gone with a different idea. However, I'll be looking over your code
to 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 and
test 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.WindowConstan ts.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.WindowConstan ts.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.TRAILI NG,
> 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
>
> }


 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      01-26-2008
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.
 
Reply With Quote
 
Hal Vaughan
Guest
Posts: n/a
 
      01-26-2008
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 it
something like 5 seconds so I could click the button, then switch to my
text editor. The first time I just typed and kept my focus on the text
editor until I realized the window had already opened, then scanned what I
had typed and there were no missing characters. The next few times I just
kept tapping the space bar since I've seen that trigger JButtons and there
was 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 other
stuff from other experiments in the way. At least now we know your way is
simple and works!

Hal
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
window.focus() brings source code into focus Spizzat2 Javascript 2 01-09-2008 03:45 PM
emulating window.focus in Body onload() event and setting focus to a control on same page Jason ASP .Net 4 05-07-2007 05:54 PM
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
focus on the new window.open window Csaba Gabor Javascript 4 12-01-2005 10:20 AM
Grabbing text from a Java window David W. Thomas Java 2 10-22-2003 11:29 AM



Advertisments