我现在做了一个项目,要求在主页显示的时候有菜单选项、工具栏,并且要有个背景图片,我做好了之后发现工具栏在出来后显示在整个框架上,将背景图片给挡住了,我拖动工具栏,背景图片又出来了,我该怎么做才能把工具栏固定在菜单选项下面并且不许拖动呀?我的主要目的是工具栏不要影响背景的显示!

解决方案 »

  1.   

    我是用ImageIcon实现的我也试过来设置工具栏的绝对位置,可是结果还是不成!我现在是相当的郁闷,今天老总就要检查了!各位大侠帮帮忙呀!谁有类似的代码没有呀?借来参考参考,谢谢了!
      

  2.   

    代码比较多,我选了其中的重要部分,请看看:
    package UserMain;import java.awt.AWTException;
    import java.awt.Color;
    import java.awt.MenuItem;
    import java.awt.PopupMenu;
    import java.awt.SystemTray;
    import java.awt.TrayIcon;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.ScrollPaneLayout;
    import javax.swing.UIManager;import Commont.DataBaseOperate;
    import Commont.FormatInformation;
    import MenuInfor.FileInduction;
    import MenuInfor.StudentInduction;
    import ResultConstrue.ClassResult;
    import ResultConstrue.GradPlace;
    import ResultConstrue.ResultCheck;
    import SystemOperata.RunUserChat;public class AfterLogin {
         private SystemTray systemTray;
         public void show(){
              final JFileChooser JFile = new JFileChooser();
              JLabel myabel;
              //主界面
               final JFrame frame = new JFrame(FormatInformation.frame);

              ((JPanel) frame.getContentPane()).setOpaque(false);
              ImageIcon img = new ImageIcon(FormatInformation.ImageBackground);
              JLabel background = new JLabel(img);
              frame.getLayeredPane().add(background, new Integer(Integer.MIN_VALUE));
              background.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());          JMenuBar menuBar = new JMenuBar();

              //*******************************************************************************
              //文件处理阶段
               JMenu menuInfor = new JMenu(FormatInformation.menuInfor);
              //文件导入
               JMenuItem induction  = new JMenuItem(FormatInformation.induction);

              //文件导出
               JMenuItem deriving  = new JMenuItem(FormatInformation.deriving);

              //文件报表打印
               JMenuItem printing  = new JMenuItem(FormatInformation.printing);

              //导入学生成绩                      
               JMenuItem inductResult  = new JMenuItem(FormatInformation.inductResult);
       
              //退出系统管理
               JMenuItem exitSystem = new JMenuItem(FormatInformation.exitSystem);
        
              //**********************************************************************************
              //下载管理
               JMenu download = new JMenu(FormatInformation.download);
              //下载题库
               JMenuItem downloadSubject = new JMenuItem(FormatInformation.downloadSubject);
        
              //下载成绩
               JMenuItem downloadResult = new JMenuItem(FormatInformation.downloadResult);
              menuBar.add(menuInfor);
              menuBar.add(download);

              frame.setJMenuBar(menuBar);
           
              menuInfor.add(induction );
              menuInfor.add(deriving);
              menuInfor.add(printing);
              menuInfor.add(inductResult);
              menuInfor.addSeparator();
              menuInfor.add(exitSystem);

              download.add(downloadSubject);
              download.add(downloadResult);
              JToolBar toolBar = new JToolBar();
              JButton button1,button2,button3,button4,button5,button6,button7,button8;
              button1 = new JButton("按班级查询");
              button2 = new JButton("按年级统计");
              button3 = new JButton("按班级统计");
              button4 = new JButton("按学科统计");
              button5 = new JButton("题型");
              button6 = new JButton("错题统计");
              button7 = new JButton("查看错题库");
              button8 = new JButton("系统退出");

              toolBar.add(button1);
              toolBar.add(button2);
              toolBar.add(button3);
            toolBar.add(button4);
            toolBar.add(button5);
            toolBar.add(button6);
            toolBar.add(button7);
            toolBar.add(button8);
    frame.add(toolBar);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,600);
    frame.setLocation(150,80);
    frame.setVisible(true);
    frame.setIconImage(new ImageIcon(getClass().getResource(FormatInformation.pictureURL)).getImage());
        } 
        public static void main(String []args){
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception exception) {
             exception.printStackTrace();
            }
    AfterLogin aLogin=new AfterLogin();
    aLogin.show();

    }
    }
      

  3.   

    对于java来做GUI ,确实不好调整,我也没有具体办法,先帮你顶了,我也想学习一下
      

  4.   

    好象是要覆盖Jpanel的paint方法
      

  5.   

    楼上的,一看就知道你对API不熟悉