How to share same Input Method across multiple windows in (Java Swing) - java

I want to make all Windows open in a Java swing application sharing same language InputMethod, that is, changing InputMethod in one window will result InputMethod changing in every other Window.
I have tried to create a single global InputContext and override getInputContext() of each window to return that Context, but it's not working reliably for some language input methods. Any idea?

Related

How to make sure the user does not able to do any other thing once my window is shown in linux/mac [duplicate]

How can I disable OS-level keyboard shortcuts (e.g. Alt-Tab, Ctrl-Alt-Left/Right, etc.) on a [Ubuntu] Linux machine? I'm developing a full-screen Java Swing app and don't want the user to be able to task switch away from the program arbitrarily. It's not enough to toggle the "always on top" flag; users mustn't be allowed to switch workspaces, migrate focus or any other such things. The machine must function normally before and after the application is executed. Google says that this will require JNI or JNA but I'm looking for a bit more hand-holding.
There's no point in trying to do this in your application because any of these changes are going to need to be handled by X11 and/or the window manager since those are what respond to the commands. Assuming that you have control of the platform, choose a window manager which supports a kiosk mode. Then use the window manager's settings to start your application and enter kiosk mode.
Options for window managers which can do this include KDE or twm-kiosk.
(And if you don't have control of the platform, you're not likely to be able to have your application intercept things like ctrl-alt-backspace anyway.)
Edit:
In response to a scaled-down version of the question in which he's willing to let things like ctl-alt-backspace go and just wants most of the keys including alt-tab or other similar application switching key combinations, the following should work:
You should be able to do this using XLib's XGrabKeyboard method through JNI. This Java/XLib JNI keypress capture tutorial should be a good starting point. However, it uses XGrabKey which just passively listens for keys and does not prevent other applications from receiving them. You'll instead want to use XGrabKeyboard which actively snags all of the normal keyboard events (which, if the premise of this StackOverflow question is correct, includes the task switching keys).
Note that as a side-effect, key capture in Swing will also probably stop working because your Swing windows are going to be separate from the window you create in C. As such, you will probably have to use your JNI interface to get key presses to your program when needed. (Although I would definitely advise testing it first before writing the code.) You might be able to avoid this if you can get the window using Java AWT Native Interface to get the window ID. (Note that Swing is built on top of AWT, so this will work for Swing.) However, I'm not sure how to do this. It looks like you might be able to navigate the window tree by getting the root window from the Display and going from there to find your Window, but it's all kind of weird. It would be nice if the AWT NI just told you the window ID, but it doesn't look like it does that.
As this warning Reminder: XGrabKeyboard is not a security interface notes, this doesn't make it impossible for other programs to see the keys, but it seems likely that window managers will not be using XQueryKeyMap so it is likely to prevent task switching.

A way to examine a separate java application's GUI buttons/labels/etc

I'm looking for a program, application, or some way to examine a java application, and be able to view its GUI information. This would include buttons, labels, panels, and list information. Ideally you could examine things by using the mouse pointer, and either hovering over an object or clicking on it. The separate program or application could display things like type of object, object name, and position of object in a console or a window.
I've found some applications that can examine a java application if it's using the Java Access Bridge, but I'm looking for a way that does not require the target java application to have the JAB.
Java Native Interface (JNI) allows you to get mouse clicks, positioning, and keyboard presses, but it does not appear to return information, like button names, inside a java application. Any ideas?
Answers to this question will be highly subjective, depending on the type of GUI technology used and the personal views of the answering person.
That being said, when I do JavaFX development, I use ScenicView. It works really well in my experience and can be loaded a number of different ways. It has most of the features you mentioned and displays a ton of data about the GUI objects, as well as highlighting the selected object's boundaries.

Handling events in multiple windows of the same applet

What is the best way to handle events (enable or disable button) or share parameters across different windows that are opened of the same applet ?
I am not referring to the browser window, instead (run as applet) window in the local IDE.
Which can be the best method to handle this scenario and let the other window know that the event has occurred already and proceed to the next step ? Here, there are no multiple applets. Just one applet, one code base, but multiple instances created.
Java uses a model, view, controller system. The model would be the variables under the hood, the view would be the applet, and the controller would be the buttons and other interactions. Many of the Swing components take a variable(model) in the constructor and automatically update with that. If you want to alert a specific function that a variable has been changed by any button, use property change listeners.
http://docs.oracle.com/javase/tutorial/uiswing/events/propertychangelistener.html

Multiple similar GUI windows java

I am working with JFrame and observers. I have a functioning GUI with multiple buttons and functions.
I am trying to create a button which opens a new window, that is exactly the same as the main window. All changes in any window, should be automatically updated to all open windows.
Any help how to begin?
General suggestions:
Use Model-View-Control or MVC design pattern,
use a factory method to create your sub-views (or as you call them, windows), createWindow(Model model), and
give each sub-view the same shared model object.

Binding a JavaFX variable to a Java variable/object

I am writing a JavaFX application that contains a Java Swing GUI panel (it's the OpenBlocks workspace to be specific).
I want to detect certain events that occur in the Java Swing panel from the JavaFX side and respond to them. I have an event listener in the JavaFX environment, and when that listener "hears" an event, I want to make some JavaFX GUI object visible, so I was thinking of trying to bind the "visible" property of these objects to some variable Java variable that will update when the events of interest occur; but I tried to do this binding, and it is not working for me.
So my general question is: Is there a way to bind a JavaFX variable to a Java variable/object, and if so, how is this done?
Thank you in advance for any help on this!!! :)
In JavaFX 2.0 you can do this the javafx.beans.binding.ObjectProperty<T> (and related) classes.

Categories

Resources