This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP and have Lucian Maly on-line!
See this thread for details.
Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

How to align options vertically in JOptionaPane?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to align options vertically in JOptionaPane?

 

 
Marshal
Posts: 72478
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried setting a layout on the dialogue?
 
Master Rancher
Posts: 4256
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if you have any control over how JOptionPane showOptionDialog method displays the contents of the array.  You may have to write your own dialog window.
 
Rancher
Posts: 3232
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The layout of the option pane is controlled internally, and there are no methods to directly control the layout of the buttons.

So, the proper solution is to just create a custom modal JDialog that displays the components based on your requirements.

However, if you really want to use the JOptionPane functionality then you would need to:

1. create the JOptionPane as a Swing component and then change the layout manager of the panel containing the buttons.
2. add the JOptionPane to a JDialog and implement the standard option pane functionality manually.

The first step is demonstrated below:


The above code searches for the buttons that have been added to the option pane and then finds the parent container and changes the layout manager of the container to be a GridLayout. You will also need the  SwingUtils class.

To implement the second step you will need to Read the API for the JOptionPane. It contains the code necessary add the code to a JDialog and implement the option pane functionality.

 
That's a very big dog. I think I want to go home now and hug this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic