Disabling everything while swingworker is working? - java

I have searched the net and can't find the specific thing that would help me out. I have my Swing Worker class doing some work in the background, while that is happening i would like to disable everything on my UI.
I don't want to go from one button to the next (Jlist, Jtable) etc and disabling everything. is there an easier way; Like drawing something on top of my UI and then removing it when Swing Worker is done? can somebody show me how to do something like that. Or what would be your suggestion.
I already know how to get a notice when Swing Worker is done. just looking for the best way to disable everything.

Best would be to parse your JFrame.getChildren() in a recursive manner.
But you could also use a GlassPane- see Root Panes

Related

How to create simple GUI in Nuklear with minimum amount of code?

I need to create simple GUI using Nuklear and Java. I just need a couple of buttons and radio buttons. When I click on them, on the screen should appear short text. Unfortunately I found nothing about that on the Web.
It wouldn't be anything hard to do if I could using Swing or something like that, but Nuklear is necessary :/
Could anybody help me with that and explain/show example of one button in window?
Regards :)

Block Swing pop-up from losing focus and closing

I'm developing a plugin for IntelliJ IDEA, which obviously uses Swing.
For a feature I have introduced I'd like to stop a JPopupMenu which uses JCheckBoxMenuItems from losing focus and closing.
You can see it in action.
I've debugged the code, but I couldn't figure out how to do it, also being I'm not that into Swing.
Could you maybe point me to useful listeners/blocks of code/ways to prevent this?
If you want to see code, the IntelliJ classes are
ActionPopupMenuImpl.MyMenu
ActionMenuItem
Edit: a better way need to be found as the uiRefreshed event isn't always called at the right time.
Just coordinate your code in a good way ;)
The Swing mechanism in IDEA is too complicated, and maybe it's better to not touch it. Just know that the mouse events are handled by a special listener and then redirected to Component(s).
That said, having an hold on the menu ActionButton. You can listen for the Lookup's uiRefreshed event and programmatically:
myMenuButton.click()
That's all.
You need to call it after the UI has been refreshed because the LookupUi might have changed in dimension or location.

What is the more performant order of adding Components in Swing

I need to refactor my application, since I'm running into rendering issues which are probably a result of not properly using the event dispatch thread. In order to do things right, I try to gather information. I already started this thread, which was about the EDT:
When exactly are components realized in Swing
Now I would like to know more about the best way to nest Panels.
Let's say I have the following structure:
[PanelA [PanelB [PanelC ]]]
What would be more performant (less internal calls to invalidate())
Order 1 (first inner components then outer):
PanelB.add(PanelC);
PanelA.add(PanelB);
Order 2 (first outer components then inner):
PanelA.add(PanelB);
PanelB.add(PanelC);
If someone also has more info/links/hints etc on how to get the most performant UI I would really appreciate that. Most Tutorial just explain the basics.
A related question:
Since all JComponents are Containers, I consider saving some JPanels, by adding components to let's say a JButton. Is this good practice:
JButton b=new JButton();
b.setLayout(new BorderLayout(),BorderLayout.Right);
b.add(new MyComponent());
How can I know which layout a Component uses by default and what could possibly happen, when I change the Component's Layout?
Thanks a lot for your help.
You should not worry about the order of adding the components, the difference will not be noticeable to the user.
You should not worry about the performance of the UI in general. Swing code in itself will be "fast enough". Performance/responsiveness gets interesting only if you are starting long-running non-UI tasks from the UI.
If you add panels to buttons, it will confuse the user. You can check the source code of the components to see their layout managers (but this is very rarely necessary)

Key event not captured in Applet AFTER I've pressed one of my GUI buttons

I have music Applet which uses keyboard, mouse and GUI buttons. When applet is first loaded keyboard events work fine, as do mouse events. However, after I have pressed one of my GUI buttons the mouse events still work but the keyboard events don't, and don't start working again until I refresh the applet.
After hunting around on the net I found some posible solutions, I've tried adding button.setFocusable(true); and button.addKeyListener(this); to all my buttons, and and my panels. No effect at all. I've seen recommendations for converting to a JApplet and using key binding, but surely there must be a simpler way?
Sorry for the lack of code, I've been working on this project since I was a newbie and it's a bit of a mess, and very long!
Any help much appreciated!
button.setFocusable(true); and button.addKeyListener(this); to all my buttons
For JButton use Swing Action or default implementations for ActionListener, rather than KeyBindings (for Swing based Container and JComponents), nor using KeyListener
EDIT
if isn't there really important reasons, don't use prehistoric AWT Applet, use JApplet, may be sufficient would be plain JFrame
Try to cut the problem area out of your project and put it here. Its highly probable, than while localizing the problem area you'll find some errors already.
If your project is a mess already, then the first and the most important thing you should do, is to order it. If it is a mess for you, that means you don't understand it. So, it simply can't work. That is your first and main error.

Java - disable DEFAULT_LAYER of JLayeredPane

I've got a JLayeredPane where my MODAL_LAYER is neatly covering the everything, and it's all generally going pretty well.
But there's a fly in the soup - the layers underneath still have functionality, even though they're visually hidden by the MODAL_LAYER.
Is there a neat way to "turn off" the lower layers, or pass all functionality to the MODAL_LAYER, or similar?
Seems like an easy question, maybe I'm having one of those moments.
EDIT
It may be possible to deny focus to any below layers, similar to JDialog, where nothing is allowed to happen except for direct interaction with the dialog?
You could use a glass pane and intercept events that don't go to a component of your modal layer. See http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html

Categories

Resources