高手指点 在一个界面上添加了按钮想在按钮上插入图片但是图片却不能显示望高手们指教!!!谢谢~~~~~~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请先看看用JBuilder生成的代码package 图书馆管理系统1;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.awt.Graphics;import javax.swing.ImageIcon;import javax.swing.Icon;import com.borland.jbcl.layout.*;public class Frame1 extends JFrame { ImageIcon img; ImageIcon img2; JButton a=new JButton(); //Construct the frame public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { img = new ImageIcon("123.jpg"); img2= new ImageIcon("555.jpg"); a.setBounds(new Rectangle(577, 273, 42, 95)); a.setIcon(img2); a.setFont(new java.awt.Font("Serif", 1, 20)); a.setForeground(Color.red); a.setText("guanglichu"); JPanel panel = new JPanel() { public void paintComponent(Graphics g) { g.drawImage(img.getImage(), 0, 0, null); super.paintComponent(g); } }; panel.setDebugGraphicsOptions(0); panel.setOpaque(false); panel.setLayout(null); setContentPane(panel); this.setResizable(false); this.setSize(700,525); panel.add(a); a.validate(); this.getContentPane().add(panel,null); this.setTitle("图书馆欢迎你"); this.setVisible(true); } //Overridden so we can exit when window is closed protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } }}很奇怪的是,在按钮上能插入图片“123.jpg”但是却不能插入图片“555.jpg” package net.xiaohai;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;/** * @author haihai * */public class TestMain extends JFrame { private JButton b=null; private JPanel panel=null; private ImageIcon i=null; public TestMain() { super("带图片按钮"); b=new JButton("button",new ImageIcon("E:\\1006.jpg"));//图片绝对路径 panel=new JPanel(); panel.add(b); this.getContentPane().add(panel); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(300, 250); this.setLocationRelativeTo(null); this.setVisible(true); } public static void main(String[] args) { new TestMain(); }} 结果得出了应该是我的图片555.jpg问题不过还是谢谢大家 换成其他图片的话就可以在按钮上显示我的那张图是用QQ本身的那个截图工具截得的,而且又比较小,然后我把它转换为jpg格式但是我用其他截图工具截的同样一副图(尺寸大一点),却能显示。所以我想是图片问题 关于可变数目的参数的问题 苦恼中 再问个小白问题..谁能给我解释下堆内存和盏内存..最好可以浅显点的解释. 引入别一个包中的类出错,谢谢大家 那位大哥有sun.net.ftp 的技术文档…………? java有没有方法从内存中去掉某些已经加载的类? 2个String类型的对象如何比较值相等 CORBA with Java java中同时对一个文件建立读写流时,为什么有时候出现问题呢 千万帮兄弟一把~~~~!! 文件名后綴到底有多少種呢﹖能自由設置嗎﹖謝謝﹗﹗ java新手的问题 真的很困惑 求结 线程问题!
package 图书馆管理系统1;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import com.borland.jbcl.layout.*;
public class Frame1 extends JFrame { ImageIcon img;
ImageIcon img2;
JButton a=new JButton();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK); try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
img = new ImageIcon("123.jpg");
img2= new ImageIcon("555.jpg");
a.setBounds(new Rectangle(577, 273, 42, 95));
a.setIcon(img2);
a.setFont(new java.awt.Font("Serif", 1, 20));
a.setForeground(Color.red);
a.setText("guanglichu");
JPanel panel = new JPanel() {
public void paintComponent(Graphics g) {
g.drawImage(img.getImage(), 0, 0, null);
super.paintComponent(g);
}
}; panel.setDebugGraphicsOptions(0);
panel.setOpaque(false);
panel.setLayout(null);
setContentPane(panel);
this.setResizable(false);
this.setSize(700,525);
panel.add(a);
a.validate();
this.getContentPane().add(panel,null); this.setTitle("图书馆欢迎你");
this.setVisible(true);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
很奇怪的是,在按钮上能插入图片“123.jpg”但是却不能插入图片“555.jpg”
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;/**
* @author haihai
*
*/
public class TestMain extends JFrame {
private JButton b=null;
private JPanel panel=null;
private ImageIcon i=null;
public TestMain() {
super("带图片按钮");
b=new JButton("button",new ImageIcon("E:\\1006.jpg"));//图片绝对路径
panel=new JPanel();
panel.add(b);
this.getContentPane().add(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 250);
this.setLocationRelativeTo(null);
this.setVisible(true);
} public static void main(String[] args) {
new TestMain();
}
}
应该是我的图片555.jpg问题
不过还是谢谢大家
我的那张图是用QQ本身的那个截图工具截得的,而且又比较小,然后我把它转换为jpg格式
但是我用其他截图工具截的同样一副图(尺寸大一点),却能显示。
所以我想是图片问题