//设置一个按钮为一个图片,不要border ImageIcon searchIcon = ImageToolkit.loadImageIcon(/search.png"); ImageIcon searchHoverIcon = ImageToolkit.loadImageIcon("/search_hover.png"); ImageIcon searchPressIcon = ImageToolkit.loadImageIcon("/search_press.png"); searchBtn = new JButton(searchIcon); searchBtn.setRolloverEnabled(true); searchBtn.setRolloverIcon(searchHoverIcon); searchBtn.setPressedIcon(searchPressIcon); searchBtn.setBorderPainted(false); searchBtn.setContentAreaFilled(false); searchBtn.setFocusable(false); searchBtn.setRequestFocusEnabled(false); searchBtn.setPreferredSize(new Dimension(18, 18)); searchBtn.setOpaque(false); searchBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { enterPressed(); } });