Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Disabling the close-button on a JDialog  (Read 4498 times)
0 Members and 1 Guest are viewing this topic.
Offline Captain Awesome

Junior Member


Medals: 2


Hi


« Posted 2011-01-06 22:27:47 »

Is this possible? I know you can use setDefaultClosingOperation, but I want to make the button "disabled/grayed out" so that it actually looks disabled.
I have googled for a while now and still haven't found an answer to this.
Offline BoBear2681

JGO Coder


Medals: 18



« Reply #1 - Posted 2011-01-07 04:40:48 »

Assuming you have a custom JDialog with some contents you control, can't you just call:

1  
cancelButton.setEnabled(false);


?
Offline CommanderKeith
« Reply #2 - Posted 2011-01-07 05:11:05 »

If you're talking about the X button in the top left corner that kills a window on windows, I've never seen it greyed out in a java app or seen an option to make it do that.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2011-01-07 21:47:41 »

It is possible. Look at the child components, find this button and call setEnabled(false) on it.

Offline CommanderKeith
« Reply #4 - Posted 2011-01-08 00:11:41 »

It is possible. Look at the child components, find this button and call setEnabled(false) on it.

Have you tried this? I doubt it is that easy because the button is in the title bar which is platform specific and thus the buttons are abstracted away and hidden from us programmers.

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2011-01-08 03:11:58 »

Hm... I know you can setUndecorated(true) on a window to hide that entire bar, but I'm not sure how to gray it out. However, I've seen it done so I know it's possible. Just look around in JContainer, JWindow, etc. and see if there is some method that looks like that.

See my work:
OTC Software
Offline BoBear2681

JGO Coder


Medals: 18



« Reply #6 - Posted 2011-01-08 04:39:31 »

It is possible. Look at the child components, find this button and call setEnabled(false) on it.

Have you tried this? I doubt it is that easy because the button is in the title bar which is platform specific and thus the buttons are abstracted away and hidden from us programmers.

I believe it's possible with LookAndFeels that support painting their own window decorations, such as Metal and perhaps Substance, but for others (WindowsLookAndFeel for example), you're right that the native window frame and widgets are used, and in that case they cannot be modified.  Code to grab components from the title bar in Metal can be found on the old forum.java.sun.com Swing forum.
Offline Mr_Light

Senior Member




shiny.


« Reply #7 - Posted 2011-01-08 05:33:27 »

At this point you need to step back and ask yourself if your actually going to achieve what you want to achieve - graying out a closing button is going to break user expectations and users might even think your application is unresponsive. I suggest to either have it and use it or remove it.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #8 - Posted 2011-01-08 14:24:28 »

At this point you need to step back and ask yourself if your actually going to achieve what you want to achieve - graying out a closing button is going to break user expectations and users might even think your application is unresponsive. I suggest to either have it and use it or remove it.

Good point.

An application should be cleanly user-interruptible at any stage.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline Captain Awesome

Junior Member


Medals: 2


Hi


« Reply #9 - Posted 2011-01-08 14:32:14 »

Thanks for your answers, guess I'm stuck with the normal close-button Sad
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JL235

JGO Coder


Medals: 10



« Reply #10 - Posted 2011-01-09 05:28:05 »

the native window frame and widgets are used,
Actually I believe this is not entirely true (at least it is for some components). For example there is a well known MacOS Swing look and feel bug where it fails to render the JTree 100% correctly (I believe it's missing an animation), and pre-Vista versions of Java fail to render correctly on Vista and Win7 (I believe because they didn't fully support the new Windows look and feel). It's a copyright restriction that makes the various platform specific Swing look and feels platform specific.

So you might be able to hack the different platform specific look and feels to look greyed out. Making the close window action do nothing can be done without hacking it.

Although I agree with the others that you should not hack it. Whatever your 'no' or 'cancel' option is, have closing the dialog perform the same thing.

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #11 - Posted 2011-02-24 04:44:48 »

the native window frame and widgets are used,
Actually I believe this is not entirely true (at least it is for some components). For example there is a well known MacOS Swing look and feel bug where it fails to render the JTree 100% correctly

Yeah, I guess I meant "native window frame and that frame's decorations," i.e. the close/restore/minimize buttons on Windows, were "native" when using the WindowsLookAndFeel, not other standard components such as JTree.  For example, call UIManager.getLookAndFeel().getSupportsWindowDecorations() when using the MetalLookAndFeel vs. WindowsLookAndFeel.  Metal is capable of rendering a JFrame's title bar itself, and when it does, you can walk the component hierarchy and indirectly access a Component used for its "close" button.  With WindowsLookAndFeel, you cannot do that.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!