在JTable&amp ;;下添加背景图像一个JButton

时间:2013-04-02 18:45:48

标签: java swing jtable jframe jpanel

我真的尝试过每一个教程,例子并查看每个帖子,以便为我的课程添加背景图片。然而,图像只是放在JTable&的JButton!

非常感谢一些指导,我再次尝试使用stackoverflow上的每个链接来解决这个问题。

这是我班级的代码:

package game;

public final class HighScores {

    private JFrame frame;

  public HighScores() throws FileNotFoundException, IOException{

    frame = new JFrame();
    frame.setTitle("The Birds Game - High Scores");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    JLabel Lbl = new JLabel("The Birds Game", JLabel.CENTER);
    frame.add(Lbl,BorderLayout.NORTH);


    JButton mainMenu = new JButton("Main Menu");
    mainMenu.setFocusable(false);
    frame.add(mainMenu, BorderLayout.SOUTH);
    mainMenu.setBackground(Color.lightGray);
    mainMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainMenuButtonActionPerformed(evt);
            }
        });
    frame.setSize(600, 500);
    frame.setResizable(false);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }

  /** mainMenu button action*/
  private void mainMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
      frame.dispose();
      new Main().setVisible(true);
  }
}

另一个问题我正在使用Jtable占据Frame中的所有空间我希望它居中,但是要做到这一点我需要将它添加到面板但是如果我将它添加到面板而不是框架面板倍增三次!

感谢您的支持!

0 个答案:

没有答案
相关问题