• 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

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

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> How do you go through all the components.

 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I have got that to work, and have a JFrame without its buttons.
 
Manoj Paul
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes its working ... thank you all my friends... great help..

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic