• 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

Maximize button in JDialog

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
Is there any way to put a maximize button in a JDialog window?
Yes, it MUST be a JDialog, and yes it MUST have a maximize button (or else i get fired )!
So can you help me out on this?
Thanks a lot!
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way to put a maximize button in a JDialog window?
No. Not really.
Yes, it MUST be a JDialog, and yes it MUST have a maximize button (or else i get fired )!
Maximizing a JDialog is kind of against the purpose of a JDialog. So whoever is going to fire you if this won't work is probably over paid. If you could give a brief explination as to why you need a JDialog to have a maximize button, then I bet we can come up with a viable alternative.
For example, you could put your own JButton on the JDialog that, when pressed, increases the size of the JDialog to the entire screen. It just wouldn't be the fancy little button on the Frame border.
 
Joel de Matos
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am currently responsible for some error-fix tasks on a large project, so i can't just change things for every problem that i have to fix.
This would explain why i can't change from a JDialog to a JFrame, as the behaviour of a JDialog is expected.
My JDialog has a button inside that shows a little more info that is hidden by default. The thing is when i press that button, my JDialog always needs to be resized for everything to fit inside, so i have to put a maximize button there as the need to always resize the window is unacceptable for the client.
Maybe some different kind of window would be a lot better to implement this feature but, like i said, this is a big project with a lot of dependencies and i can't just change things around to make my life easier...
I hope i was clear, my english is not very good :roll:
Thanks a lot!
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could call pack() on the dialog right after you add all the new widgets to it. This will make the dialog resize itself to be big enough to hold all the widgets on it. If there are any custom components or scrollpanes you might have to make sure they are returning an appropriate preferred size or the dialog will size itself smaller than it needs to be.

You don't have to hack native MFC code to add a button to a dialog it doesn't need, you don't have to make the user manually change the size of the dialog, and best of all - you don't get fired!
 
Joel de Matos
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If there are any custom components or scrollpanes you might have to make sure they are returning an appropriate preferred size or the dialog will size itself smaller than it needs to be.


Unfortunatly this is what is happening.
I tried to pack it but the window gets smaller
I am using this constructor:
Dialog(Frame owner, String title, boolean modal)
Should i try to get the size of my components and then resize the window "manualy" or is there a way to get the window to get the size of those components?
Thanks so much for your help!
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What for you need to maximize the dialog, since the size of the JDialog increases the size with the length of message in it.
sallu
 
Joel de Matos
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, i really have to implement the maximize button in JDialog.
There is a possibility of changing the JDialog IF AND ONLY IF i can ensure that the new window will have the same behaviour.
This is what i have:
A JDialog with a button, two scrollables inside and some other non-editable text boxes.
The data in both scrollables can get bigger than the window if the button is pressed (the button makes new data to appear in both scrollables).
After some discution it was decided that a maximize button must be provided with the window. I can change what i want BUT the window must keep its behaviour.
So my question here becomes a little different:
What is the best way to implement a JDialog with a maximize button?
Build a JFrame and setting it to modal?
I am no expert in swing so i hope you can help me.
Thanks
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't make a truly modal frame. The closest you are going to get is add a window focus listener to the launching frame that moves the "dialog" frame to the front if it ever loses focus -


There are still some problems with this because it isn't truly modal... users can still click on the title bar of the launching frame really fast and do things like maximize it or exit it.

I still think that putting a maximize button on the dialog is the wrong way to go about this... why have the user manually change the size of the window when it can be performed automatically....

Just set a preferred size on the scrollpanes... the data inside may get "bigger than the window", but that's why you are using *scroll* panes, so the user can *scroll* through a long list of data.

Something like this -


Or are you building special GUI panels inside the scrollpanes? I would do away with the scroll panes altogether if this is the case, and just use pack() to make sure all the components are visible.
 
Joel de Matos
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well i did it with dynamic resize (it would be so much better...) but, as we say in Portugal (and other places too), "The customer is always right".
This simple code shows it:

Now seriously, on the scrollables point, the user wants to maximize the window so he doesn't have to resize it for the cases that the information gets bigger than the window, but still fits on the screen.
If the information gets wider than the screen, he will scroll through it.
The modal feature is not so important because despite my class constructor has a boolean argument to decide if the window will be or not modal, it is always invoked with modal = false (i think that the guy who made the original class just put it there for some future development, and in that case, i really won't bother myself too much with it), so i'll just set my frame to be always on top with this code: (Is it good?)

Thanks for all your support!
I really appreciate your help as i always learn something more with your replys!
 
reply
    Bookmark Topic Watch Topic
  • New Topic