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!
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.
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!
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!
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
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!
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
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!
Looky! I'm being abducted by space aliens! Me and this tiny ad!