Results 1 to 3 of 3
Thread: Multiple Line Input Dialog Box
- 05-31-2007, 09:26 PM #1
Super Moderator
- Join Date
- Apr 2007
- Posts
- 30
- Rep Power
- 0
Multiple Line Input Dialog Box
I've got a simple dialog box that I'm creating by calling
I get a little edit box where the user can enter a simple string, and this works fine.Java Code:JOptionPane.showInputDialog(...)
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?
- 05-31-2007, 09:27 PM #2levent Guest
Here's something to play around with. It's a bit rough, but it might be enough to get you started.
Java 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; } }
- 05-31-2007, 09:30 PM #3
Super Moderator
- Join Date
- Apr 2007
- Posts
- 30
- Rep Power
- 0
Similar Threads
-
Creating a dialog to input user/password
By prfalco in forum New To JavaReplies: 4Last Post: 02-18-2008, 07:03 AM -
Example of SWT Dialog
By Java Tip in forum Java TipReplies: 0Last Post: 01-09-2008, 12:01 PM -
JOptionPane - input dialog
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:09 AM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM -
how to take input and verify input in Java programs
By bilal_ali_java in forum Advanced JavaReplies: 0Last Post: 07-21-2007, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks