Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
input errors in JDialogs
Barry Brashear
Ranch Hand
Posts: 303
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 128
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Struts 2 reditect to same URL
Same Code Different Behaviour
struts-config.xml parse error
can't get selectManyCheckbox values
No result defined for action
More...