Java,Swing - cannot draw lines on a JFrame -


i'm trying draw vertical lines separate days in week on jframe. code seems fine no error when run it, output frame picture below. missing anything?

public class weektoview extends jframe{     public weektoview(){      settitle("sheffield dental care"); //set title     toolkit toolkit = toolkit.getdefaulttoolkit();      dimension screendimensions = toolkit.getscreensize();     setlocation(new point(screendimensions.width*1/4, screendimensions.height*1/4)); //set location based on screen size      jpanel container = new jpanel();     jscrollpane scrpane = new jscrollpane(container);     getcontentpane().add(scrpane);     double size[][] = {{150, 150, 150, 150, 150}, // columns             {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100}}; // rows     container.setlayout(new tablelayout(size));      string daysinweek[] = {"monday", "tuesday", "wednesday", "thursday", "friday"};     jlabel daysinweeklabels[] = new jlabel[daysinweek.length];      (int = 0; < daysinweek.length; i++) {         daysinweeklabels[i] = new jlabel(daysinweek[i],swingconstants.center);     }      container.add(daysinweeklabels[0], "0,0");     container.add(daysinweeklabels[1], "1,0");     container.add(daysinweeklabels[2], "2,0");     container.add(daysinweeklabels[3], "3,0");     container.add(daysinweeklabels[4], "4,0");      setsize(780,600); //set size based on screen size     setdefaultcloseoperation(jframe.exit_on_close);     setresizable(false); //unresizable     setvisible(true);     }     public void paintcomponent(graphics g) {         super.paint(g);         graphics2d g2 = (graphics2d) g;         g2.setrenderinghint(renderinghints.key_antialiasing, renderinghints.value_antialias_on);          g2.drawline(getwidth()/5,0,getwidth()/5,getheight());         g2.drawline(getwidth()*2/5,0,getwidth()*2/5,getheight());         g2.drawline(getwidth()*3/5,0,getwidth()*3/5,getheight());         g2.drawline(getwidth()*4/5,0,getwidth()*5/5,getheight());    } } 

enter image description here

there no paintcomponent() method in jframe. whenever attempt override method should use @override before method name. compile error if don't override method correctly.

you override paint() in general don't try custom painting in paint() method of jframe.

instead custom painting done overriding paintcomponent() method of panel add frame.

better yet can use jtable, provides row/column based component.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -