How can I get metadata from secific window in MS Windows 8 / 10 (using java) [on hold] - java

Hi I writinig simple app under MS Windows 8 / 10 in Java 7
I need metadata from specific window
component.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {
// I would like to get info about window I click
by "metadata" i mean specyfic (clicked by mouse) MS window name, id, position, size (and another data form clicked MS window)
So, my question is if exist any java library ("kind of bridge") with allow java application access to data with contain MS window


How to detect right-click event for Mac OS

For windows and linux I am able to detect right click. But for mac I donot know how to detect right-click.
How to write java program to detect right click for Mac OS
Sunil KUmar Sahoo
It's the same as detecting a right-click on Windows or Linux—you call your given MouseEvent's getButton() method to check if BUTTON3 was clicked. For example, take a look at the following snippet of an example MouseListener:
public class MyListener implements MouseListener
// ... code ...
public void mouseClicked(MouseEvent event)
if (event.getButton() == MouseButton.BUTTON3)
// Right-click happened
However, this only detects right-clicks if the user actually has a two-button mouse. Since most Mac mice had only one button as of not-too-long-ago, you might want to consider detecting Control-clicks as well (which was the common idiom for right-clicking back then). If you decide to do so, the implementation is pretty trivial: just add another check for if event.isControlDown() returns true.
Instead of using MouseEvent.BUTTON3, a bettter self docummenting approach is to use
if (SwingUtilities.isRightMouseButton(event))
// do something
Also, if you are using this code to display a popup menu, then you should not be using this approach since each OS has different key strokes to inovoke the popup menu. Read the section from the Swing tutorial on Bringing Up a Popup Menu.
Control-click support needs to be added as Mac users might not be using a mouse with second button - e.g. A trackpad doesn't have a right mouse button.
public void mouseClicked(MouseEvent e) {
// Mac often uses control-click - isControlDown()
if (SwingUtilities.isRightMouseButton(e) || e.isControlDown()) {
// do something
private static boolean isRightClick(MouseEvent e) {
return (e.getButton()==MouseEvent.BUTTON3 ||
(System.getProperty("").contains("Mac OS X") &&
(e.getModifiers() & InputEvent.BUTTON1_MASK) != 0 &&
(e.getModifiers() & InputEvent.CTRL_MASK) != 0));
SwingUtilities.isRightMouseButton() will not work. It is incorrectly implemented for the Mac ctrl-click example because it checks whether e.getModifiers() & 0x4 is non-zero. But the flag used for "command" is also 0x4.
So it will report cmd-click as a right-click but won't report ctrl-click as one. Worse yet, cmd-click will also return true to SwingUtilities.isLeftMouseButton(). If your code is written to handle left-clicks one way and right-clicks another, and you use a second if rather than an else if, you're in for a nasty surprise when both execute.
For those who are interested, these are the complete getModifiers() and getModifiersEx() values for single-modifier clicks.
Left click: (button 1)
Basic: 0000010000 0000000000 16 0
Shift: 0000010001 0001000000 17 64
Ctrl: 0000010010 0010000000 18 128
Cmd: 0000010100 0100000000 20 256
Opt: 0000011000 1000000000 24 512
Mid click: (button 2)
Basic: 0000001000 1000000000 8 512
Shift: 0000001001 0001000000 9 64
Ctrl: 0000001010 0010000000 10 128
Cmd: 0000001100 0100000000 12 256
Opt: 0000001000 1000000000 8 512
Right click: (button 3)
Basic: 0000000100 0100000000 4 256
Shift: 0000000101 0001000000 5 64
Ctrl: 0000000110 0010000000 6 128
Cmd: 0000010100 0100000000 20 256
Opt: 0000001100 1000000000 12 512

How to get x and y position of user click in Eclipse plugin + RCP

I am developing a plugin for email client using JFace + RCP using Eclipse. I am not developing any screens using eclipse, mail client will be the screen for this plugin.
I want to get the user clicked position in client.
You can use the addFilter method of Display to add a listener that is called for all mouse down events in the SWT code:
Display display = Display.getDefault();
display.addFilter(SWT.MouseDown, new Listener()
public void handleEvent(Event event)
System.out.println("event " + event);
if (event.widget instanceof Control) {
Control control = (Control)event.widget;
System.out.println("display " + control.toDisplay(event.x, event.y));
The Event passed to handleEvent has x and y fields for the mouse down event - these are relative to the control containing the event. The control is given in the widget field. I have shown code to convert these values to be absolute display values.
Note: This only works for mouse down events in the current application and only for SWT code. In the past Lotus Notes used a lot of native code where this would not work, I don't know if this is still the case.

netbeans setDefaultCloseOperation

I am trying to set the default close operation in NetBeans 8.0.2 (in Ubuntu 14.04 on an older Asus gaming laptop.) My program is very large but uses no JFrame or java.swing components.
I merely need to save some values when the "x" in the lower right corner is clicked (this is one usual way to stop execution of a java program in NetBeans.)
I found suggestions that involved swing & JFrame, but it wasn't clear just where to insert the code:
DefaultApplicationView view = new DefaultApplicationView(this);
javax.swing.JFrame frame = view.getFrame();
frame.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent e){
I also found a set of instructions that I think I would prefer to use, but the post is old enough that my NetBeans doesn't have the tabs/menu-items referred to:
Set Window to Design Mode by clicking the 'Design' Tab
In the Navigator: Right click the 'JFrame' -> 'Properties'
In the Properties Tab: Set 'defaultCloseOperation' (top of the list) to 'DO_NOTHING'
Select 'Events' Tab
Scroll down to 'windowClosing'
Click on the "..." button on the right of the event to bring up the custom editor
Click 'Add...' and name the handler (i.e. custom function that you want to have execute on click of the 'X', or window close event).
Click 'Ok'
Netbeans now automatically creates the function and takes to you the function body in the source view
Now simply add what you want to do here: eg. dispose(), or system.exit or pintln(), or whatever your heart desires, as long as its JAVA and makes sense to the app.
Then there are a few other possibly relevant posts, but they all explicitly involve JFrame and/or swing. (Am I ignorant of some fact such as "All NetBeans java applications use JFrame", or some such?)
A pared down example of code for what I'm trying to do would be:
public class MyApp{
public static void main(String[] args){
// do some work that changes variables' values
// during this work user clicks the 'x' box to halt execution
// I need then automatically to save the variables' new values
// needs to be called by the OS or GUI when execution is halted by user
public static void saveMyVariables{
// here the usual printStream stuff saves some values to a file
public static void loadMyVariables{
// here the usual Scanner stuff reads some values from a file
(I need help setting the tags for this, so I'm doing as instructed and asking the community.)

Make TrimmedWindow as Application Model

I'm using eclipse e4 and I want to create an application model named TrimmedWindow which I can use as a custom dialog, but I don't want the user to use background windows (block the events) while the dialog is open. Is there any way I can do that with e4?
public void execute(MApplication application) {
MTrimmedWindow mWindow = MBasicFactory.INSTANCE.createTrimmedWindow();
//how to set application model so that it blocks access to other background windows?
mWindow.getPersistedState().put(IPresentationEngine.STYLE_OVERRIDE_KEY, String.valueOf(SWT.APPLICATION_MODAL));

Java how to keep same windows layout after a program restart

Hi I have a java GUI application which shows table and allow user to move column and resize them. The problem is that each time I exit and restart the application, column place and size are back to default. Is there a mean to keep it as what it was before exiting the application?
any link to ref on the subject would be appreciated. thank you
I would record this info and store it using the Java Preferences API. Capture the resize using something like:
TableColumn col=table.getColumnModel().getTableColumn(colNumber);
col.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(PropertyChangeEvent e) {
// has the column width changed ?