java - JMenuBar does not appear in JFrame -
solved forgot instantiate menubar...
i have extended class jmenubar
, , class jframe
. however, when setjmenubar(menubar)
, menubar not appear in frame
when testing.
here's code:
class frame:
import javax.swing.jframe; public class frame extends jframe{ public static menubar menubar; public frame(){ settitle("lol teamcomps"); setlocationrelativeto(null); setdefaultcloseoperation(exit_on_close); setjmenubar(menubar); } }
class menubar:
import javax.swing.jmenubar; import javax.swing.jmenuitem; import com.lolteamcomps.code.components.menuitem; public class menubar extends jmenubar{ public menubar(){ jmenuitem players = new jmenuitem("players"); jmenuitem champions = new jmenuitem("champions"); jmenuitem newplayer = new jmenuitem("add new"); jmenuitem newchampion = new jmenuitem("add new"); players.add(newplayer); champions.add(newchampion); add(players); add(champions); } }
and in function called in main:
private static frame frame = new frame(); public static void createwindow(){ frame.pack(); frame.setvisible(true); }
only empty frame
appears, nothing in it. doing wrong?
edit: own thought setjmenubar(menubar)
won't work, because menubar
not jmenubar
, menubar extends jmenubar
, in fact jmenubar
, right? also, don't error @ line, don't think case. thought.
you need instantiate menubar
public menubar menubar=new menubar(); public frame(){ .... setjmenubar(menubar); }
Comments
Post a Comment