Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 19-01-2010
Member
 
Join Date: Dec 2009
Posts: 178
JOptionPane.showInputDialog size list

Hello.
I use dialogs with lists (of String []) that appears in drop down list. No problem for this but according to the lists they appear on multiple lines or one line each time with a scroll (normal for a combo ). In fact I would have 4 to 5 lines that appear in the list and not a number of line of dependent, I do not know what parameter.
Here is a model code that I use for my dialogs:
Code:
 String mncon = (String) JOptionPane.showInputDialog(
fen, "Choose your contact", "Contact List."
, JOptionPane.QUESTION_MESSAGE, null, mncon, mncon[0]);
mncon is an array of String. Is there a way of determining the number of items to display in the combo? Thank you for your responses.

Last edited by New ID : 19-01-2010 at 12:08 PM.
Reply With Quote
  #2  
Old 19-01-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: JOptionPane.showInputDialog size list

Hello,
Good is to use UI that manages it.
Quote:
It is up to the UI to decide how best to represent
* The <code> selecvals </ code>,
* <code> JCombox </ code>, <code> JList </ code>, or
* <code> JTextField </ code> will be used.
Is there any solution to it, I'm interested. Meanwhile I continue to look for another solution.
Reply With Quote
  #3  
Old 19-01-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: JOptionPane.showInputDialog size list

Hi,
The parameter "message" of JOptionPane is not necessarily a String, but can take several forms. You especially can pass a component that will be displayed directly, or chart to display multiple elements on top of each other. So it becomes simple to make your own dialog box, with custom components that you want.
Reply With Quote
  #4  
Old 19-01-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: JOptionPane.showInputDialog size list

Hello,
Just have a look at the below example, it can help you.
Code:
Public static String showContactListDialog(ParentComponent Component, Object[] options, Object initialValue) {
		/ / Create the JList containing the items:
		JList ls = new JList(Options);
ls.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		
		/ / On the square in a scrollPane size desired:
		JScrollPane scls = new JScrollPane(ls);
scls.setPreferredSize(new Size(220,280));
		
		/ / It sets the initial val:
		ls.setSelectedValue(initialValue, true);
		
		/ / Create the content of our dialogue:
		/ / Message 1 + scrollpane containing the ls:
		Object[] message = { "Choose your contact", ScrollList };
		
		/ / Use showOptionDialog () interface which offers the most complete
		int resp = JOptionPane.showOptionDialog(
				parentComponent, message "Contact List.",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
				null, null, null);
		
		/ / And we treat the return val:
		String val = null;
		if (resp == JOptionPane.OK_OPTION) {
			val = ls.getSelectedValue().toString();
		}
		return val;
	}

Last edited by Zecho : 19-01-2010 at 12:09 PM.
Reply With Quote
  #5  
Old 19-01-2010
Member
 
Join Date: May 2008
Posts: 2,383
Re: JOptionPane.showInputDialog size list

Hello,
Quote:
scrollList.setPreferredSize(new Size(220,280));
The above is correct, but you can also use setVisibleRowCount as an alternative to the above, though both are correct.
Quote:
/ / scrollList.setPreferredSize (new Dimension (220, 280));
list.setVisibleRowCount(5);
Hope this gives an alternative and so that you can use it in your code in future, if needed
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 19-01-2010
Member
 
Join Date: Dec 2009
Posts: 178
Re: JOptionPane.showInputDialog size list

Hey,
The solution works, I modified a bit to add title and caption variable. By cons, and I understand why, with the modification is was not working, I have not 5 lines that appear but half a line. In fact, with the list.setVisibleRowCount (n) I must multiply the number of line n by 10 (approximately) for n even my lines desired. Actually it works for my other lists, this "bug" just a list (obviously that's the one with which I made my test ). By the thanks guys for your help.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "JOptionPane.showInputDialog size list"
Thread Thread Starter Forum Replies Last Post
Use of JOptionPane class Khan Baba Software Development 5 16-02-2010 11:44 AM
How Can I Change the background Color Of A JOptionPane? Adrina_g Software Development 5 27-01-2010 09:41 AM
Joptionpane in java Xmen Software Development 2 14-11-2009 12:20 PM
Can't make checked list box and listbox in same size Recko Software Development 3 06-08-2009 01:56 PM
The logical size of this database is 16 GB. This database size is approaching the size limit of 18 GB HandelMan Small Business Server 3 18-04-2007 04:26 PM


All times are GMT +5.5. The time now is 11:34 PM.