• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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

 
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: 10528
224
  • 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: 480
6
IntelliJ IDE Spring Fedora
  • 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: 3069
24
  • 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: 3462
149
  • 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: 708
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: 480
6
IntelliJ IDE Spring Fedora
  • 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: 202
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: 65447
248
  • 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.
 
today's feeble attempt to support the empire
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!