• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Attempting to remove the "close" button on a JFrame object  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I am coming with a question that has been asked and answered before, but with a twist. I have followed the examples shown in the link provided, but am having an issue recursively finding the AbstractButton objects. I am using a Java based IDE called Processing with the G4P library which is useful in creating GUIs.


Below is my code:




When I run the above code I get the following output for each Component found on the JFrame:




In the forum that I mentioned previously, recursively looping through the JFrame components and remove the buttons was relatively straightforward. That was also 12 years ago, so I'm assuming some structural changes may have happened with Swing.

Does anyone know why I'm not able to find the Button objects here? or how to go about doing it?


Thank you,
Grayson
 
Saloon Keeper
Posts: 10240
216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably because they're not JButtons. Why do you want to do this in the first place? Let users use their windows the way they want.
 
Rancher
Posts: 427
6
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a property to just get rid of it? In windows forms or wpf you can get rid of the top right buttons with a simple change of the property.
 
Rancher
Posts: 3040
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

There isn't a property to just get rid of it?


No.

The easiest solution is to just use:


 
Saloon Keeper
Posts: 3253
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or alternatively, add a WindowAdapter to your sub frame, and in the windowClosing method, invoke a method of your main frame, so that that frame can decide what to do, depending on the circumstances.
 
Bartender
Posts: 706
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can call setUndecorated(true) on your frame. Note, however, that doing so will remove ALL of the decorations, making it impossible for the user to resize or move the frame.
 
Al Hobbs
Rancher
Posts: 427
6
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so there is a property to get rid of them.
 
Ranch Hand
Posts: 163
5
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another way: use a Frame instead of a Window

Window default to have decorated to true, wich add title-bar and therefore the minimize/maximize and closing buttons
a Frame doesn't have these but only provide the native peer provided by the system windowmanager so you can draw anything yourself on it

other way around: why do you want have the closing button removed insread of propper handle its event? smells like bad design - rethink about what you want to accomplish instead of try to get rid of unwanted provided funcionality
 
Marshal
Posts: 64494
225
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Matt Wong wrote:. . . use a Frame instead of a Window

Window default to have decorated to true, wich add title-bar and therefore the minimize/maximize and closing buttons
a Frame doesn't have these but only provide the native peer provided by the system windowmanager so you can draw anything yourself on it.
. . .

Are you sure that is the right way round? A JFrame has buttons and a title bar; a JWindow doesn't. Have a look in the Java™ Tutorials.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!