This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane Customisation  RSS feed

 
Phil Collier
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'm writing a small application, It has a search functionality and my aim is to have a JOptionPane with 2 JCheckboxes, A JTextField, and 2 JButtons.
The check boxes are for the selection of an exact or near match search.
Is there anyone who knows how to achieve this, or any other way. I know I can just create a JFrame to do the job but that is a last resort.
Thanks to anyone who can help
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Phil,
The JOptionPane has 4 areas; icon, message, input and buttons.
You can pass in different objects to the constructor, not just Strings.
try a showInputDialog dialog where the selection valies are an array of 3 vectors of 3 strings and observe what happens.( it throws the string representation of the vectors into a JCombo for you )
Trick is to look at the return values of the many constructors for JOptionPanes. With the above example when the user selects an option you have a reference to the selected object and you can now use that to do your tasks...
Hope that helps,
Terry
 
Phil Collier
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you advice Terry, however, I have previously used your suggested method in other applications. My aim is to minimise the number of clicks the user has to go through to achieve their task. If I used the method suggested the user would have to select the searh type from the combo box, click ok, then another JOptionPane would be needed for the user input. I wanted to try and get it all on one option pane. Do you know how I could possibly achieve this with a JDialog?
Thanks again for your reply.
Phil Collier
 
Bhushan Jawle
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Phil,
You can do that by using "static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) " of JOptionPane.
In this you need to create your required components in a suitable container e.g. JPanel and pass it on as parameter named message which is and Object.
This should do the job.
Regards,
Bhushan
 
Phil Collier
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, i'll try that right away, and i'll let you know if i was successful.
 
Phil Collier
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhushan, it looks like i'm in business! Just needs a few alterations and i'm there. Thanks again for your input.
Phil Collier
 
Bhushan Jawle
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U r welcome Phil
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!