|
|
|
|
|
|
|
|
|
|
Re: User Interface example projects [message #1773121 is a reply to message #1773111] |
Thu, 21 September 2017 21:14 |
Erhy More Messages: 7 Registered: September 2017 |
Junior Member |
|
|
Thank you so much!
This was the key for me.
My first rudimentary code:
package com.vogella.swt.widgets.layout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class SWTLayoutPositionTracker {
// TODO Auto-generated method stub
static String newLine = System.getProperty("line.separator");
private static Label positiongLabel;
private static Shell shell;
public static void main(String[] args) {
Display display = new Display();
shell = new Shell(display);
positiongLabel = new Label(shell, SWT.BORDER);
int x = 60;
int y = 20;
int width = 400;
int height = 70;
positiongLabel.setBounds(x, y, width, height);
Font font = new Font(positiongLabel.getDisplay(), new FontData("Mono", 10, SWT.ITALIC));
positiongLabel.setFont(font);
positiongLabel.setToolTipText("This is the tooltip of this label");
Button button = new Button(shell, SWT.PUSH);
button.setBounds(x, y + height + 20, width, height);
button.setText("press this button\n-results in output on console");
// register listener for the button selection event
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
System.out.println("Button pressed!");
}
});
int toolbarSize = 30;
shell.setBounds(200, 400, width + 2 * x, height * 4 + y + toolbarSize);
shell.open();
shell.addMouseMoveListener(e -> showSize(e));
positiongLabel.addMouseMoveListener(e -> showSize(e));
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
public static void showSize(MouseEvent e) {
int x = e.x;
int y = e.y;
String s = "Bounds for Label: " + positiongLabel.getBounds() + newLine;
s += "Bounds for Shell: " + shell.getBounds() + newLine;
s += "Mouse pointer: " + x + " " + y;
positiongLabel.setText(s);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.08885 seconds