Home arrow static arrow Java Programming [Archive] - NEW FORUM MEMBER WITH A QUERY
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - NEW FORUM MEMBER WITH A QUERY
1 Duke Stars available
This topic has 38 replies on 3 pages.    1 | 2 | 3 | Next »

Posts:59
Registered: 6/28/04
NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 10:39 AM



 
I am having most annoying problems with my GUI as far as verifying input.I am using a javax.swing.InputVerifier on several text fields -- the verification demands are beyond what I can doing with a JFormattedTextField also. The problem seems to arise from a default button on my dialog -- pressing enter activates the button without giving the InputVerifier a chance to veto this process.

Is there anything I can do to make this work properly?
 

Posts:24,036
Registered: 2/3/03
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 10:43 AM (reply 1 of 38)



 
Please be a little more explicit about what you're doing, what you expect to happen, and what you actually observe.

Please post a short, concise, executable example of what you're trying to do. This does not have to be the actual code you are using. Write a small example that demonstrates your intent, and only that. Wrap the code in a class and give it a main method that runs it - if we can just copy and paste the code into a text file, compile it and run it without any changes, then we can be sure that we haven't made incorrect assumptions about how you are using it.

Post your code between [code] and [/code] tags as described in [url=http://forum.java.sun.com/features.jsp#Formatting]Formatting Help[/url] on the message entry page. Cut and paste the code, rather than re-typing it (re-typing often introduces subtle errors that make your problem difficult to troubleshoot). Please preview your post when posting code.
 

Posts:59
Registered: 6/28/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 10:55 AM (reply 2 of 38)



 
I am sorry that my previous post seems so vague. Here is an example which I am now writing.
Please notice that pressing enter when focus is on either text field, both being associated
with an InputVerifier, yet pressing the enter key causes the default button to be clicked upon
with the InputVerifier given any chance to verify input. Is it wrong to have a default button, also?
import java.awt.*;import java.awt.event.*;import javax.swing.*; public class InputVerified {    public static void main(String[] args) {        InputVerifier iv = new InputVerifier() {            public boolean verify(JComponent input) {                String text = ((JTextField)input).getText();                System.out.println("ic called with text = " + text);                return true; //accepted            }        };         JPanel panel = new JPanel();        JTextField field1 = new JTextField("field 1", 8);        field1.setInputVerifier(iv);        panel.add(field1);        JTextField field2 = new JTextField("field 2", 8);        field2.setInputVerifier(iv);        panel.add(field2);        JButton btn = new JButton("default button");        btn.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent evt) {                System.out.println("button clicked");            }        });        panel.add(btn);         JFrame f = new JFrame();        f.setContentPane(panel);        f.getRootPane().setDefaultButton(btn);        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        f.pack();        f.setVisible(true);    }}
 

Posts:5,627
Registered: 3/22/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:10 AM (reply 3 of 38)



 
Hai VishnuPunjabi or should I say, Kidda, paaji?

I would not listen to that Yawmark chap. He is always causing problems. One day he was criticizing me about one Level 42. He is also having one doubt about Kajagoogoo.

Wo muunda kam ne karddhaa hai.

I hope that helps.
 

Posts:59
Registered: 6/28/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:25 AM (reply 4 of 38)



 
Sri Filestreamji,
You are into 1980's pop music, no doubt? Really I am in Blondie cover band. My tabla solo on
"Heart of Glass" is beyond compare.
 

Posts:24,036
Registered: 2/3/03
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:26 AM (reply 5 of 38)



 
LMFAO.
 

Posts:24,036
Registered: 2/3/03
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:28 AM (reply 6 of 38)



 
filestream, I always knew there was something about you...
 

Posts:24,036
Registered: 2/3/03
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:29 AM (reply 7 of 38)



 
filestream, I always knew there was something about you...

That is, when you're not acting too shy (shy - you understand)...
 

Posts:5,627
Registered: 3/22/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:35 AM (reply 8 of 38)



 
Sri Filestreamji,
You are into 1980's pop music, no doubt? Really I am
in Blondie cover band. My tabla solo on
"Heart of Glass" is beyond compare.

Yai bakwas hai! Achee bat sah bolo!

Heart of Glass is **** and we all know it. If you were to mention "The Tide is High" or "Call Me", we would be impressed, but that "Heart of Glass"? Utter nonsense.
 

Posts:5,627
Registered: 3/22/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:38 AM (reply 9 of 38)



 
filestream, I always knew there was something about
you...

That is, when you're not acting too shy (shy - you
understand)...

As for you My West Des Moines Friend. All you want to do is Colour By Numbers during Sunday services in the Church of the Poison Mind.
 

Posts:59
Registered: 6/28/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:46 AM (reply 10 of 38)



 
He is also having one doubt about Kajagoogoo.

"Kajagoogoo"? Is this Malayalam you are speaking? But don't judge quickly Blondie. With the right
rag, Heart of Glass is massive.
 

Posts:24,036
Registered: 2/3/03
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:52 AM (reply 11 of 38)



 
As for you My West Des Moines Friend. All you want to
do is Colour By Numbers during Sunday services
in the Church of the Poison Mind.

Do you really want to hurt me? Is that why you're giving me Looks that Kill? You should know that your Bad Attitude just Cuts Like a Knife.

...but it feels so right...
 

Posts:59
Registered: 6/28/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 11:56 AM (reply 12 of 38)



 
Cuts Like a Knife ...but it feels so right...

Achaa, a little 80's fun is fun, but don't try my patience with Mr. Bryan Adams!
Are there any serious forum members out there?
 

Posts:5,627
Registered: 3/22/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 12:24 PM (reply 13 of 38)



 
Vishnu,

Okay, seriously.... Don't set the default button. It is causing the problems that you see. By default, the defaultbutton will respond to the UI event of enter unless you have another component set to consume that event.

What this means is your default button is responding to enter key (as you told it to) and the JTextFields don't have a chance to verify input.

Comment it out and all will be well.

Good luck, Sat Sri Akal.

P.S. Me and some guys from school, had a band and we tried real hard.
 

Posts:5,627
Registered: 3/22/04
Re: NEW FORUM MEMBER WITH A QUERY  
Jun 28, 2004 12:25 PM (reply 14 of 38)



 
What the hell...my Engrish was lousy in that last post!
 
This topic has 38 replies on 3 pages.    1 | 2 | 3 | Next »