java - JavaFX 8 Screen resolution doesn't update when program is running -


for reason when print laptop's resolution width using screen.getprimary().getvisualbounds().getwidth()); right result of 1920. if print resolution width, change resolution 1680x1050 in windows settings, ask thread wait minute, , print resolution width again using same code, 1920 instead of 1680! however, if stop project, set resolution 1680x1050, compile , run project, print 1680. in other words seems project doesn't update resolution if change while project running.

below javafx code illustrate mean. if run code below, watch print 1920, change resolution real quick, wait until thread done sleeping, described before still print 1920 instead of new resolution width.

public class main extends application {     @override     public void start(stage primarystage) throws exception {         system.out.println(screen.getprimary().getvisualbounds().getwidth());         thread.sleep(60000);         system.out.println(screen.getprimary().getvisualbounds().getwidth());     }     public static void main(string[] args) { launch(args); } } 

the problem has polling screen resolution on same thread. if new thread created, told sleep while user changes screen resolution in windows settings, , told print screen resolution screen, resolution reflect updated resolution.

if user ran following , changed resolution while thread asleep correct updated resolution print screen, unlike code in original question.

public class main extends application {     @override     public void start(stage primarystage) throws exception {         system.out.println(screen.getprimary().getvisualbounds().getwidth());         new thread(){             public void run() {                 try{                     this.sleep(30000);                 } catch (interruptedexception e) {                     // ignore                 }  system.out.println(screen.getprimary().getvisualbounds().getwidth());             }         }.start();     }     public static void main(string[] args) { launch(args); } } 

another solution reflects updated screen resolution use awt. following print correct updated resolution,

public class main extends application {     @override     public void start(stage primarystage) throws exception {  system.out.println(java.awt.toolkit.getdefaulttoolkit().getscreensize());         thread.sleep(30000);  system.out.println(java.awt.toolkit.getdefaulttoolkit().getscreensize());     }     public static void main(string[] args) { launch(args); } } 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -