swing - Java - Screen turns black, when setting a JFrame to Fullscreen -


i'm trying draw on canvas, add jframe , set jframe fullscreen. problem is: in fullscreenmode see black screen. before screen turns black shortly can see pink background of canvas.

drawing directly on jframe , setting fullscreen works fine , can see testtext. assume there problem displaying canvas properly.

here code:

public class fullscreentest extends canvas {      private jframe mainframe;      public fullscreentest(){         this.mainframe = new jframe();         jpanel contentpane = (jpanel) mainframe.getcontentpane();         contentpane.add(this);     }      public void run(displaymode dm){         setbackground(color.pink);         setforeground(color.white);         setfont(new font("arial", font.plain, 24));          screen s = new screen();          s.setfullscreen(dm, this.mainframe);          try {             thread.sleep(5000);         } catch (interruptedexception exc) { exc.printstacktrace(); }          s.closefullscreenwindow();     }      public void paint(graphics g){               g.drawstring("this testtext", 200, 200);     }      public static void main(string[] args){         displaymode dm = new displaymode(800, 600, 32, displaymode.refresh_rate_unknown);         fullscreentest test = new fullscreentest();         test.run(dm);     } } 

here screen.setfullscreen(displaymode dm, jframe window) method does:

//graphicsdevice = graphicsenvironment.getlocalgraphicsenvironment() //                 .getdefaultscreendevice(); public void setfullscreen(displaymode dm, jframe window){     window.setundecorated(true);     window.setresizable(false);     graphicsdevice.setfullscreenwindow(window);      if(dm != null && graphicsdevice.isdisplaychangesupported()){         graphicsdevice.setdisplaymode(dm);               } } 

does have clue why don't see jframe's content in fullscreen?

1) have 3 general issues

  • never block edt using thread.sleep(5000); use swing timer instead, demonstrations here

  • (if aren't there important reasons) don't mixing awt swing rest here, , use jpanel instead of canvas (for canvas there paint method, jpanel there paintcomponent)

  • your public void paint(graphics g){ jframe instead of canvas , locked thread.sleep(5000);

2) swing gui rellated should wrapped invokelater() meaning

public static void main(string[] args){ 

more in initial thread

3) in linked code example can find out demostrations how use background thread in swing


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -