no focus for key events in swt - java

I'm currently having problems with SWT KeyEvents. In an RCP application I have several controls that will be focused if you are tabbing through, e.g. first toolbar icon, another one, finally the editor and a class which is in the editor (a composite, it'll be focused as well).
This particular class receives key events; only - of course - if it is focused and I need to process these events (remember this class gets focus after the editor was focused because the editor holds an instance)
Is there any way to guarantee that this composite will have focus if for example the mouse is over this area?
Already tried to solve this with MouseEvents but even then setFocus() does not always provide focus (same goes for forceFocus()).

Related

How to "Unclick" a JButton without releasing the left mouse button?

I have set up a mouse dragged listener. I trying to set it up where you can click one button then drag your mouse over others to click the other ones. The problem I am having is when you click the first button it turns grey like its waiting for you to release the mouse button. When you move your mouse off the button (still holding the left mouse button) it returns back to its normal color but you cant highlight anything until you let go. Is there anyway to simulated letting the mouse go and "unclicking" the button so you can highlight other things?
What you observe is the typical behavior of the ButtonModel used by Swing buttons. A complete example is examined here, but note how the effect depends on the chosen Look & Feel's ButtonUI delegate.
To get the effect you want, you would have to create buttons using your own variation of BasicButtonUI and a custom ButtonModel that uses isRollover() to add buttons to your program's notion of a selection model.
As an alternative, consider JList, which contains a ListSelectionModel that allows MULTIPLE_INTERVAL_SELECTION. A compete example is shown here.

Detecting a user-initiated column resize in SWT

How can I tell when a column is resized by the user in an SWT TreeViewer? I initially thought it would be via ControlAdapter, but this also fires on initialization and if the application window gets resized.
Is it more appropriate to add a drag or mouseup listener? It doesn't seem (to me) that the TreeColumn initially supports this kind of behavior.

Determine if focusedProperty change is permanent in JavaFX

In Java's AWT FocusEvent class:
There are two levels of focus events: permanent and temporary.
Permanent focus change events occur when focus is directly moved from one Component to another, such as through a call to requestFocus() or as the user uses the TAB key to traverse Components.
Temporary focus change events occur when focus is temporarily lost for a Component as the indirect result of another operation, such as Window deactivation or a Scrollbar drag. In this case, the original focus state will automatically be restored once that operation is finished, or, for the case of Window deactivation, when the Window is reactivated.
In JavaFX, a ChangeListener can be added to the focusedProperty as shown here, but how does one determine if the change is permanent?

Leave Swing JMenuBar tree open after selecting certain elements

I am currently in the process of self-teaching myself Java through the very comprehensive and readable text by Horstmann and Cornell published by Sun (8th ed/Vol 1. ISBN: 978-0-12-235476-9) and through completing one of the Swing examples (Listing 9-8) I noticed an annoying action performed upon selecting "Toggle" menu items.
The example shows toggling between certain options using the JCheckBoxMenuItem and JRadioButtonMenuItem classes. I noticed that upon selection of one of those menu components, the entire tree traversed closes. Is there a way to stop this menu closing through either a settable property of the items, or a method called in the ActionListener provided?
Link to authors code dump: Here
Cheers for any response. Would be a nice tweak to chuck into UI implementation further down the line.
not possible from Java6, for JPopup used for JMenu and JComboBox, popup is hidden from mouse a keyboar events
could be possible for custom popup for JMenu/JComboBox based on (undecorated) JDialog or JWindow, with JButtons (in your case with JCheckBox/JRadioButtons) layed by GridLayout

Control of JLabel

I have built, with a GUI builder, a set of JLabels and 4 arrows in a JFrame. I want, when I press one of the arrows to be able to perform operations on the correspondent label. I.e when the control is on the first label the "right" arrow would "bring" the control on the right label. I also want to mention that due to GUI builder I can't(??) use array and increase/decrease the pointers. Any ideas?:)
It sounds like you are trying to pair your GUI too closely to your data. When someone clicks on a button, it should perform some action on your data. Once that action is complete, the GUI should be updated to reflect the new data. This is much easier than moving controls within the window. This is known as the Model View Controller pattern.
Read the section from the Swing tutorial on How to Use Key Bindings. In general, this allows you to define an Action that is executed when a KeyStroke is invoked. So you can have a different Action for each of the right/left/up/down arrow keys.

Categories