JMenu einträge werden überdeckt

Status
Nicht offen für weitere Antworten.

Randall

Bekanntes Mitglied
Folgendes Problem:

In meinem Hauptfenster werden die aufklappenden Menueinträge (es handelt sich um ein JMenu) vom Content Pane überdeckt. Wieso das?

Code:
	public Starter(String title){
		super(title);
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent evWindow)
			{System.exit(1);}
			});
				
		contentPane.setLayout(new GridBagLayout());	
		
//		Die Hauptmenuleiste wird erstellt	
	   
				 menubar = new JMenuBar();
				 menubar.setBackground(Color.LIGHT_GRAY);		
				 menubar.add(createFileMenu());
				 menubar.add(createAdminMenu());
				 menubar.add(createViewMenu());
				 menubar.add(createHelpMenu());	
				 
				 setJMenuBar(menubar);			
	}


Was muss ich tun, damit das aufklappende Menu im Vordergrund steht und benutzt werden kann?
 
Sorry... hab die Methode für die Untermenueinträge vergessen ..hier ist sie also.


Code:
// Menu Datei mit Untermenüs
	
	private JMenu createFileMenu (){
				
		JMenu dat = new JMenu("Datei");
		dat.setMnemonic('d');
		dat.setBackground(Color.PINK);
		dat.setForeground(Color.BLACK);
		JMenuItem mi;
		
//Oeffnen
		mi = new JMenuItem ("Oeffnen", 'f');
		setCtrlAccelerator(mi, 'f');
		mi.setBackground(Color.PINK);
		mi.setForeground(Color.BLACK);
		mi.addActionListener(this);
		dat.add(mi);
		
//Speichern
		mi = new JMenuItem("Speichern", 's');
		setCtrlAccelerator(mi, 's');
		mi.setBackground(Color.PINK);
		mi.setForeground(Color.BLACK);
		mi.addActionListener(this);
		dat.add(mi);
		
//Seperator		
		dat.addSeparator();
				
//Beenden
		mi = new JMenuItem ("Beenden", 'b');
		mi.addActionListener(this);
		mi.setBackground(Color.PINK);
		mi.setForeground(Color.BLACK);
		dat.add(mi);
		
		return dat;		
	}
	
// Menu Administrator mit Untermenus	
	
	private JMenu createAdminMenu(){
		
		JMenu adm = new JMenu("Administrator");
		adm.setMnemonic('a');
		adm.setBackground(Color.PINK);
		adm.setForeground(Color.BLACK);
		JMenuItem mi;
		
		mi = new JMenuItem("Userverwaltung", 'u');
		setCtrlAccelerator(mi, 'u');
		mi.addActionListener(this);
		mi.setBackground(Color.PINK);
		mi.setForeground(Color.BLACK);
		adm.add(mi);
		
		mi = new JMenuItem("Codes", 'c');
		setCtrlAccelerator(mi, 'c');
		mi.addActionListener(this);
		mi.setBackground(Color.PINK);
		mi.setForeground(Color.BLACK);
		adm.add(mi);
		
		return adm;
	}
	
//Menu Hilfe mit Untermenüs	
	
	private JMenu createHelpMenu(){
		
		JMenu hlp = new JMenu("Hilfe");
		hlp.setMnemonic('h');
		hlp.setBackground(Color.PINK);
		hlp.setForeground(Color.BLACK);
		JMenuItem mi;
		
		mi = new JMenuItem("Info", 'i');
		setCtrlAccelerator(mi, 'i');
		mi.addActionListener(this);
		mi.setBackground(Color.PINK);
		mi.setForeground(Color.BLACK);
		hlp.add(mi);
		
		return hlp;
	}
	
//	Menu Anzeige mit Untermenus	
	
	 private JMenu createViewMenu(){
		
		 JMenu viw = new JMenu("Ansicht");
		 viw.setMnemonic('v');
		 viw.setBackground(Color.PINK);
		 viw.setForeground(Color.BLACK);
		 JMenuItem mi;
		
		 mi = new JMenuItem("Spenderdaten");
		 mi.setMnemonic('p');
		 setCtrlAccelerator(mi, 'p');
		 mi.addActionListener(this);
		 mi.setBackground(Color.PINK);
		 mi.setForeground(Color.BLACK);
		 viw.add(mi);
		 
		 mi = new JMenuItem("Projektdaten");
		 mi.setMnemonic('j');
		 setCtrlAccelerator(mi, 'j');
		 mi.addActionListener(this);
 		 mi.setBackground(Color.PINK);
     	                 mi.setForeground(Color.BLACK);
		 viw.add(mi);
			 
		 return viw;
	 }


Ueber Sinn und Unsinn der Menupunkte bitte nicht streiten. Ist hier mehr Versuchshalber 🙂.
 
Danke dir für den Typ. Das funktioniert so, obwohl ich eigentlich keine AWT-Komponenten im JFrame habe, nur Swing Componenten.
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben