aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to deactivate close, minimise and resizable from a window say frame? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to deactivate close, minimise and resizable from a window say frame?" Watch "How to deactivate close, minimise and resizable from a window say frame?" New topic
Author

How to deactivate close, minimise and resizable from a window say frame?

Manoj Paul
Ranch Hand

Joined: Jan 18, 2007
Posts: 112
Hello everybody...

i have a window, say a JFrame, which by defalut shows the minimise, resize and close option on the right side of the window. What i want is a window which doesnt show any of the three. Can anyone help me out..

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
You can delete the title bar and buttons with the setUndecorated method but that might not be what you need.

CR
Manoj Paul
Ranch Hand

Joined: Jan 18, 2007
Posts: 112
Sorry friend, but the said method didnt worked... The title bar still shows all the three..
Is there any other method which i can try?..
Thanks for your suggestion
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Sorry friend, but the said method didnt worked... The title bar still shows
> all the three..

then you've done something totally wrong - setUndecorated(true) removes the
title bar entirely.

anyway, if you want to use
JFrame.setDefaultLookAndFeelDecorated(true);
you can then recursively iterate the frame's components, looking for the
buttons and remove them.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
Agree with Michael Dunn; the setUndecorated method removed the title bar, close button, everything.
How do you go through all the components. I tried the method you quoted and tried setWindowDecoration(JRootPane.INFORMATION_DIALOG) and still got the close button to appear.

CR
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> How do you go through all the components.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
Thank you. I have got that to work, and have a JFrame without its buttons.
Manoj Paul
Ranch Hand

Joined: Jan 18, 2007
Posts: 112
Yes its working ... thank you all my friends... great help..

ashok kandaswamy
Greenhorn

Joined: Aug 19, 2008
Posts: 16
Originally posted by Manoj Paul:
Yes its working ... thank you all my friends... great help..



hi all.

one more interesting question here..the same thing is possible with JDialogue...


Sk.Ashokkumar.....
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> one more interesting question here..the same thing is possible with JDialogue...

you are quite at liberty to try it for yourself.

post back your results.
Ron Cooper
Greenhorn

Joined: Jun 02, 2009
Posts: 3
I tried the code above with a JDialog generated by a GUI designer. The form is instantiated and populated all at once in the code.

On the first try, all the buttons were removed, even my application's ok and cancel buttons, so I decided to keep the idea similar, but to make a Vector<Component> of the buttons I didn't want to remove. It would have been nice to devise a way to do this automatically, but my time was limited, so I just added each button to the Vector in the form's constructor, created a public Vector<Component> getPreservedComponents() method in the form, and modified the removeMinMaxClose method to take the Vector of preserved buttons, and to remove only instances of AbstractButton that were not .contains()'ed in the Vector.

It would be nicer if I knew the object model well enough to specify just the min-max-close buttons. Maintaining the Vector will be a maintenance challenge.

Can anyone think of a way to identify only the min-max-close buttons, so that other application buttons are never candidates for removal?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Can anyone think of a way to identify only the min-max-close buttons,
> so that other application buttons are never candidates for removal?

call removeMinMaxClose(...) immediately after creating the frame/dialog
i.e. before you add anything to it
Ron Cooper
Greenhorn

Joined: Jun 02, 2009
Posts: 3
Michael, thank you.

When one uses a GUI builder, one may have to relinquish such fine-grained control over the form-instantiating and form-displaying operations. Netbeans, for example, instantiates the JDialog and loads up its components in an un-editable block of code. (You can edit the code, but the framework will regenerate initComponents(), so that the effect is temporary.)

Instantiating the populated dialog behaves like an atomic operation. So if I continue to use Netbeans' GUI builder (which I must), I have to do the removing after the components are pack()'ed. Unless I can think of a way to identify only the min-max-close buttons, so that other application buttons are never candidates for removal.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try changing removeMinMaxClose() to this.
if possibility of different locales, you would need to check what the accessible names change to

also note the frame needs to be resizable(false) for it to work

Ron Cooper
Greenhorn

Joined: Jun 02, 2009
Posts: 3
Michael, thanks for going the extra mile. The getAccessibleContext() was a big help!

For exploratory purposes only, I reported on the names and types of all comp objects (which had accessible contexts) processed in the code--before the check for instanceof. That helped me understand the ordering and hierarchy a little better. It was interesting to see that the buttons were processed last-in/first-out order.

I had at first thought that the icon in the upper left corner of the window must be getting removed by removeMinMaxClose(), but it turned out to have been removed by the .setDefaultLookAndFeelDecorated() .

The window icon turned out to be good riddance, because it would have provided another undesired path for exiting. The motivation for removing the close button in this program is to be certain that the user understands whether he/she is committing or cancelling the action. The program is collecting legal evidence; any uncertainty can be "lawyered" into a problem for my organization.

Thanks again for shining a light on this!
Eskay Joe
Greenhorn

Joined: Sep 24, 2013
Posts: 1
Dear Michael

how does the new function you posted in this thread

work for JFrame created by the Netbeans IDE

I mean where and how do I pass the JFrame as

an argument to the function.

The Netbeans IDE generates a class for the JFrame

extending the JFrame class

I saw through the Generated code but the JFrame

itself is just not there.

I think netbeans take care of that part of code

i.e initializing Jframe when the application is built.

So how can the above function be used there?

I have tried passing the "this" as argument to the function

that lists the jbuttons from the frame heirarchy,that is those

created by me,or the deployed objects like FileChooser etc

I have gone out of ideas.

Please mull over a bit and help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39408
    
  28
Welcome to the ranch
If you are learning Swing®, there is a simple answer to the NetBeans GUI creator and any similar programs. Don't use them.

If you do use GUI creators, never try to read their code; it is usually illegible
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to deactivate close, minimise and resizable from a window say frame?