Setting the window width/height in desktop

You must Login before you can answer or comment on any questions.

I seem to be having trouble with this. I want to make my desktop app open to the width and height of the users window. I don't want "fullscreen" as such as that hides the menu bar - at least on the Mac. By reading other posts this ought to work - but not for me.

I've tried the following code both before and after window.onload and the window size remains as set in tiapp.xml. Obviously I am missing something.

var currentWindow = Titanium.UI.getMainWindow();
currentWindow.setWidth = screen.width; 
currentWindow.setHeight = screen.height;
SDK: 1.0.1 (desktop)

3 Answers

Accepted Answer

The code

var currentWindow = Titanium.UI.getCurrentWindow();
currentWindow.setWidth = screen.width; 
currentWindow.setHeight = screen.height;
is incorrect. you actually need:
var currentWindow = Titanium.UI.GetCurrentWindow();
currentWindow.setWidth(screen.width);
currentWindow.setHeight(screen.height);
Both setWidth and setHeight are methods of the UserWindow object

— answered 2 years ago by Rob Griffiths
answer permalink
2 Comments
  • Thanks Rob, but GetCurrentWindow doesn't seem to work on Desktop as it would on Mobile. It produces an error. However setting the width and height as you have them does work, as long as one uses getMainWindow to retrieve the window object. You then have to set both the x and y positions to zero.

    — commented 2 years ago by Patrick Mounteney

  • This is not quite right.... It should use a lower case G on getCurrentWindow()

    var currentWindow = Titanium.UI.getCurrentWindow();

    — commented 1 year ago by Michael Fasani

You need to get the current window

var currentWindow = Titanium.UI.getCurrentWindow();
currentWindow.setWidth = screen.width; 
currentWindow.setHeight = screen.height;

— answered 2 years ago by Bryce Wilkinson
answer permalink
1 Comment
  • Thanks Bruce, but interestingly it doesn't want to play ball on desktop. getMainWindow() seems to be the same as getCurrentWindow() - or even if it isn't it produces the same result i.e. no change of window size. However, after some experimentation, and ignoring what the API says, it seems that a simple currentWindow.width = screen.width (missing out the 'set') does have an affect!

    — commented 2 years ago by Patrick Mounteney

Your Answer

Think you can help? Login to answer this question!