• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Resizing the JDialog when few fields are set invisible.

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have many fields in a JDialog box. And I am making some of them invisible (based on some logic).
I tried using dialog.pack();
But this was not resizing completely (To an good view). It had still spaces.

Is there any way to calculate the new size by considering the last field.
Do I need to use component.getX() and component.getY(). Or component.getWidth() and component.getHeight().. ??

Please help.

Regards,
Praveen
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
X & Y are container-relative positions (correct me if I'm wrong here, the javadocs mention this being relative to "the parent" of the component) of the top-left corner, if you want to use the size of the components to change the size of dialog, you would be correct in using getWidth() and getHeight().

You could then subtract those values from the width or height (depending on their position) of the dialog (getSize()) to resize it.

Seems like a complicated solution to me though... perhaps with more information about your dialog & problem I could suggest a better solution.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that you need to do two things here:
1) consider using a cardlayout rather than swapping components
2) read and study the layout manager tutorials in the sun Swing tutorials.

The latter was already suggested to you in the Sun Java forums though. Since many are suggesting it to you, perhaps you should take it to heart.
 
Praveen Kumar Jayaram
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ted Smyth:
X & Y are container-relative positions (correct me if I'm wrong here, the javadocs mention this being relative to "the parent" of the component) of the top-left corner, if you want to use the size of the components to change the size of dialog, you would be correct in using getWidth() and getHeight().

You could then subtract those values from the width or height (depending on their position) of the dialog (getSize()) to resize it.

Seems like a complicated solution to me though... perhaps with more information about your dialog & problem I could suggest a better solution.




Thanks for your reply.
To be in breif, I have JDialog. There are some fields which should be displayed depending on some input read from a file. What I am doing is simply having all fields on JDialog and setting not required fields to invisible. I had used dialog.pack() to resize before, but still it left some spaces. So I thought of using getHeight() for the last field displayed and setting the size of the JDialog.

I will refer some layout manager tutorials parallely. If you have some better idea, let me know.

regards,
Praveen
 
Ted Smyth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Pete's CardLayout suggestion would work best:

Have a set of fields placed into each card in a CardLayout, and simply show the card that matches the conditions from your file.

Another (slower) option is to just remove all the components in the dialog and then add the desired components it before showing.
[ July 15, 2008: Message edited by: Ted Smyth ]
 
Evacuate the building! Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic