菜单不显示
import javax.swing.JFrame;import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
class Break1 extends JFrame{
JPopupMenu mnuShortcut = new JPopupMenu();
JTextArea txa = new JTextArea();
public Break1(){
setDefaultCloseOperation( EXIT_ON_CLOSE );
jbInit();
}
private void jbInit(){
setTitle( "无标题 - 笔事本" );
JFrameSize fs = new JFrameSize( this, 50, true );
JMenuBar mnuBar = new JMenuBar();
JMenu mnuFile = new JMenu( "文件(F)" );
JMenu mnuEdit = new JMenu( "编辑(E)" );
JMenu mnuFormat = new JMenu( "格式(O)" );
JMenu mnuLookVoer = new JMenu( "查看(V)" );
JMenu mnuHelp = new JMenu( "帮助(H)" );
JMenuItem mnuNew = new JMenuItem( "新建(N)", 'N' );
JMenuItem mnuOpen = new JMenuItem( "打开(O)...", 'O' );
JMenuItem mnuSave = new JMenuItem( "保存(S)", 'S' );
JMenuItem mnuSaveAs = new JMenuItem( "另存为(A)...", 'A' );
JMenuItem mnuSetPage = new JMenuItem( "页面设置(U)...", 'U' );
JMenuItem mnuPrint = new JMenuItem( "打印(P)", 'P' );
JMenuItem mnuExit = new JMenuItem( "退出(X)", 'X' );
JMenuItem mnuUndo = new JMenuItem( "撤销(U)", 'U' );
JMenuItem mnuCut = new JMenuItem( "剪贴(T)", 'T' );
JMenuItem mnuCopy = new JMenuItem( "复制(C)", 'C' );
JMenuItem mnuPaste = new JMenuItem( "粘贴(P)", 'P' );
JMenuItem mnuDelete = new JMenuItem( "删除(L)", 'L' );
JMenuItem mnuSearch = new JMenuItem( "查找(F)...", 'F' );
JMenuItem mnuSearchNext = new JMenuItem( "查找下一个(N)", 'N' );
JMenuItem mnuTemp = new JMenuItem( "替换(R)...", 'R' );
JMenuItem mnuGo = new JMenuItem( "转到(G)...", 'G' );
JMenuItem mnuAllSelect = new JMenuItem( "全选(A)", 'A' );
JMenuItem mnuDate = new JMenuItem( "时间/日期(D)", 'D' );
JCheckBoxMenuItem mnuEnter = new JCheckBoxMenuItem( "自动换行(W)", false );
JMenuItem mnuFont = new JMenuItem( "字体(F)...", 'F' );
JCheckBoxMenuItem mnuState = new JCheckBoxMenuItem( "状态栏(S)", false );
JMenuItem mnuHelpTitle = new JMenuItem( "帮助主题(H)", 'H' );
JMenuItem mnuAboutAs = new JMenuItem( "关于笔记本(A)", 'A' );
JCheckBoxMenuItem mnuRightLift = new JCheckBoxMenuItem( "从右到左的阅读顺序(R)" );
JCheckBoxMenuItem mnuShowUnicode = new JCheckBoxMenuItem( "显示Unicode控制字符(S)" );
JMenu mnuInsertUnicode = new JMenu( "插入Unicode控制字符(I)" );
txa.setBounds( 0, 0, getWidth(), getHeight() );
getContentPane().add( txa );
mnuUndo.setEnabled( false );
mnuCut.setEnabled( false );
mnuCopy.setEnabled( false );
mnuPaste.setEnabled( false );
mnuDelete.setEnabled( false );
mnuSearch.setEnabled( false );
mnuSearchNext.setEnabled( false );
mnuGo.setEnabled( false );
mnuState.setEnabled( false );
mnuFile.add( mnuNew );
mnuFile.add( mnuOpen );
mnuFile.add( mnuSave );
mnuFile.add( mnuSaveAs );
mnuFile.addSeparator();
mnuFile.add( mnuSetPage );
mnuFile.add( mnuPrint );
mnuFile.addSeparator();
mnuFile.add( mnuExit );
mnuBar.add( mnuFile );
mnuEdit.add( mnuUndo );
mnuEdit.addSeparator();
mnuEdit.add( mnuCut );
mnuEdit.add( mnuCopy );
mnuEdit.add( mnuPaste );
mnuEdit.add( mnuDelete );
mnuEdit.addSeparator();
mnuEdit.add( mnuSearch );
mnuEdit.add( mnuSearchNext );
mnuEdit.add( mnuTemp );
mnuEdit.add( mnuGo );
mnuEdit.addSeparator();
mnuEdit.add( mnuAllSelect );
mnuEdit.add( mnuDate );
mnuBar.add( mnuEdit );
mnuFormat.add( mnuEnter );
mnuFormat.add( mnuFont );
mnuBar.add( mnuFormat );
mnuLookVoer.add( mnuState );
mnuBar.add( mnuLookVoer );
mnuHelp.add( mnuHelpTitle );
mnuHelp.addSeparator();
mnuHelp.add( mnuAboutAs );
mnuBar.add( mnuHelp );
this.setJMenuBar( mnuBar );
mnuShortcut.add( mnuUndo );
mnuShortcut.addSeparator();
mnuShortcut.add( mnuCut );
mnuShortcut.add( mnuCopy );
mnuShortcut.add( mnuPaste );
mnuShortcut.add( mnuDelete );
mnuShortcut.addSeparator();
mnuShortcut.add( mnuRightLift );
mnuShortcut.add( mnuShowUnicode );
mnuShortcut.add( mnuInsertUnicode );
txa.addMouseListener( new Mouse_mnuShortcut( this ) );
setVisible( true );
}
public void show_mnuShortcut( MouseEvent e ){
if( e.isMetaDown() ){
mnuShortcut.show( this.txa , e.getX(), e.getY() );
}
}
public static void main( String[] args ){
Break1 break1 = new Break1();
}
}
class Mouse_mnuShortcut implements MouseListener{
Break1 frame;
public Mouse_mnuShortcut( Break1 f ){
frame = f;
}
public void mouseClicked(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
frame.show_mnuShortcut( e );
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
}
菜单栏第二个子菜单前几个菜单项无法显示
搜索更多相关的解决方案:
菜单
----------------解决方案--------------------------------------------------------
//////////////////////////////////////////////////////////////////
mnuUndo.setEnabled( false );
mnuCut.setEnabled( false );
mnuCopy.setEnabled( false );
mnuPaste.setEnabled( false );
mnuDelete.setEnabled( false );
mnuSearch.setEnabled( false );
mnuSearchNext.setEnabled( false );
mnuGo.setEnabled( false );
mnuState.setEnabled( false );
/////////////////////////////////////////////////////////////////
你上面的代码使你的菜单栏里的子菜单不可显示,建议你去掉上面的代码,本人感觉毫无用处,个人意见!!!
----------------解决方案--------------------------------------------------------
这是设置菜单项是否可用和可不可看见没关系
----------------解决方案--------------------------------------------------------
JFrameSize是我自定义的类设定窗体位置和大小
----------------解决方案--------------------------------------------------------
JFrameSize是我自定义的类设定窗体居中和大小
----------------解决方案--------------------------------------------------------
我测试了下..把弹出菜单注释掉就有了..是不是资源是互坼的?还是实例的时候没注意细节?
----------------解决方案--------------------------------------------------------
这个问题解决了 谢谢大家
----------------解决方案--------------------------------------------------------