A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
input errors in JDialogs
Barry Brashear
Ranch Hand
Joined: Jun 05, 2001
Posts: 303
posted
Nov 05, 2004 06:58:00
0
What is the best idea for presenting input errors to the user in a
JDialog
?
Should you have a JLable at the bottom where you place an error message?
Thanks.
Serghei Jelauc
Ranch Hand
Joined: Jul 24, 2002
Posts: 128
posted
Nov 07, 2004 19:58:00
0
May be a did not understand the question, but why not? Of corse you can add
JLabel
to the
JDialog
. Try this:
package jdialog; import javax.swing.JFrame; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JDialog; import javax.swing.JTextField; import javax.swing.JLabel; import javax.swing.JPanel; public class Test extends JFrame{ JButton b = new JButton("Open Dialod"); public Test() { this.getContentPane().add(b, "South"); b.addActionListener(listener); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setSize(650, 500); this.setLocation(200, 200); this.setVisible(true); } ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { MyDialog dialog = new MyDialog(Test.this); } }; public static void main(String[] args) { new Test(); } } class MyDialog extends JDialog { JTextField text = new JTextField(25); JPanel textPanel = new JPanel(); JButton b = new JButton("Enter"); JLabel label = new JLabel(); public MyDialog(JFrame frame) { super(frame, "My Dialog", true); textPanel.add(text); textPanel.add(b); this.getContentPane().add(textPanel, "North"); b.addActionListener(listener); this.getContentPane().add(label, "South"); this.setSize(450, 150); this.setLocation(250, 250); setVisible(true); } ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { if (text.getText().length() > 10){ label.setText("User Input ERROR"); } else MyDialog.this.dispose(); } }; }
Hope it will help
SCJP 1.4 <br />SCBCD 1.3<br />SCWCD 1.4
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: input errors in JDialogs
Similar Threads
struts-config.xml parse error
can't get selectManyCheckbox values
Struts 2 reditect to same URL
Same Code Different Behaviour
No result defined for action
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter