Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-31-2007, 11:26 PM
Super Moderator
 
Join Date: Apr 2007
Posts: 30
johnt is on a distinguished road
Multiple Line Input Dialog Box
I've got a simple dialog box that I'm creating by calling

Code:
JOptionPane.showInputDialog(...)
I get a little edit box where the user can enter a simple string, and this works fine.

I'd like to change this so instead of a 1 line edit box, I get a multiple line edit box (I guess this would be a JTextArea). How can I do this easily?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-31-2007, 11:27 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
Here's something to play around with. It's a bit rough, but it might be enough to get you started.

Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; class Testing extends JFrame { JLabel lbl = new JLabel("Text entered = "); public Testing() { setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(600,300); setLocation(200,100); JPanel main = new JPanel(new BorderLayout()); main.add(lbl,BorderLayout.CENTER); JButton btn = new JButton("Get some text"); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ lbl.setText("<html>Text entered = <br>"+ new MyJOptionPane().showInputDialog("Enter some text").replaceAll("\\n","<br>")+ "</html>");}}); main.add(btn,BorderLayout.SOUTH); getContentPane().add(main); } public static void main(String[] args){new Testing().setVisible(true);} } class MyJOptionPane extends JOptionPane { public static String showInputDialog(final String message) { String data = null; class GetData extends JDialog implements ActionListener { JTextArea ta = new JTextArea(5,10); JButton btnOK = new JButton(" OK "); JButton btnCancel = new JButton("Cancel"); String str = null; public GetData() { setModal(true); getContentPane().setLayout(new BorderLayout()); setDefaultCloseOperation(DISPOSE_ON_CLOSE); setLocation(400,300); getContentPane().add(new JLabel(message),BorderLayout.NORTH); getContentPane().add(ta,BorderLayout.CENTER); JPanel jp = new JPanel(); btnOK.addActionListener(this); btnCancel.addActionListener(this); jp.add(btnOK); jp.add(btnCancel); getContentPane().add(jp,BorderLayout.SOUTH); pack(); setVisible(true); } public void actionPerformed(ActionEvent ae) { if(ae.getSource() == btnOK) str = ta.getText(); dispose(); } public String getData(){return str;} } data = new GetData().getData(); return data; } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-31-2007, 11:30 PM
Super Moderator
 
Join Date: Apr 2007
Posts: 30
johnt is on a distinguished road
Thanks. It works perfectly
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a dialog to input user/password prfalco New To Java 4 02-18-2008 09:03 AM
Example of SWT Dialog Java Tip Java Tips 0 01-09-2008 02:01 PM
JOptionPane - input dialog Java Tip Java Tips 0 12-17-2007 11:09 AM
Reading in data from file line by line bluekswing New To Java 1 10-02-2007 02:19 AM
how to take input and verify input in Java programs bilal_ali_java Advanced Java 0 07-21-2007 10:46 AM


All times are GMT +3. The time now is 02:56 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org