Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to properly center an e4 Application Window?
How to properly center an e4 Application Window? [message #632078] Mon, 11 October 2010 09:34 Go to next message
Matthias Heinrich is currently offline Matthias Heinrich
Messages: 7
Registered: July 2010
Junior Member
Hi,

I want to center my e4 application window (an instance of MTrimmedWindow). Currently, I call the following method in one of my parts.

@PostConstruct
public void init() {

if(app.getChildren().get(0) instanceof MTrimmedWindow){

MTrimmedWindow window = (MTrimmedWindow)app.getChildren().get(0);
Monitor primary = Display.getCurrent().getPrimaryMonitor();
Rectangle bounds = primary.getBounds();
Rectangle rect = new Rectangle(window.getX(), window.getY(), window.getWidth(), window.getHeight());
int x = bounds.x + (bounds.width - rect.width) / 2;
int y = bounds.y + (bounds.height - rect.height) / 2;
window.setX(x);
window.setY(y);

}
}


It somehow works but it resets the window each time the part get's initialized.

So I wonder if there is an option somewhere in the application model where I can specify the "center window" option.

Thanks,
Matthias
Re: How to properly center an e4 Application Window? [message #641948 is a reply to message #632078] Mon, 29 November 2010 06:00 Go to previous messageGo to next message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
Hi,

my problem is the same.
unfortunately i didn't find a proper solution either...

but you can make your code a little properer by let you injecting the window object:

@Inject
private MTrimmedWindow window;


For me the most proper way would be something like this:

Shell {
	text-align: center;
	vertical-align: middle;
}


Does anybody know the perfect way to center a window in e4?

Thanks,
Mike
Re: How to properly center an e4 Application Window? [message #642010 is a reply to message #632078] Mon, 29 November 2010 09:19 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5282
Registered: July 2009
Senior Member
You could add an Addon and listen to UI-Events and at the moment the
Shell for the MTrimmedWindow is created you center it.

Tom

Am 11.10.10 15:34, schrieb Matthias Heinrich:
> Hi,
>
> I want to center my e4 application window (an instance of
> MTrimmedWindow). Currently, I call the following method in one of my parts.
>
> @PostConstruct
> public void init() {
>
> if(app.getChildren().get(0) instanceof MTrimmedWindow){
>
> MTrimmedWindow window = (MTrimmedWindow)app.getChildren().get(0);
> Monitor primary = Display.getCurrent().getPrimaryMonitor();
> Rectangle bounds = primary.getBounds();
> Rectangle rect = new Rectangle(window.getX(), window.getY(),
> window.getWidth(), window.getHeight());
> int x = bounds.x + (bounds.width - rect.width) / 2;
> int y = bounds.y + (bounds.height - rect.height) / 2;
> window.setX(x);
> window.setY(y);
>
> }
> }
>
> It somehow works but it resets the window each time the part get's
> initialized.
>
> So I wonder if there is an option somewhere in the application model
> where I can specify the "center window" option.
>
> Thanks,
> Matthias
>
Re: How to properly center an e4 Application Window? [message #642016 is a reply to message #642010] Mon, 29 November 2010 09:39 Go to previous message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
Thank you Tom!
That sounds good.

How can i create such an addon?

Perhaps this would resolve my new problem too?:

i have a login-window witch shouldn't be resizable.
how can i prevent my window of being resized?

thans,
mike
Previous Topic:Hooking into application startup after the UI has been constructed
Next Topic:XWT Validation rules and constructors
Goto Forum:
  


Current Time: Fri Aug 22 08:03:08 EDT 2014

Powered by FUDForum. Page generated in 0.01710 seconds