怎么在文本框中显示图片,就像QQ那样.. 或者怎么才能达到这种效果 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.File;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Example extends JFrame { public Example(){ super("Example"); getContentPane().add(new JScrollPane(textPane)); JMenuBar mbar = new JMenuBar(); JMenu insertMenu = new JMenu("Insert"); JMenuItem imageItem = new JMenuItem("Image ..."); insertMenu.add(imageItem); mbar.add(insertMenu); imageItem.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ int option = chooser.showDialog(Example.this,"Pick a Image"); if (option == JFileChooser.APPROVE_OPTION){ File file = chooser.getSelectedFile(); if (file != null) textPane.insertIcon(new ImageIcon(file.getPath())); } } }); setJMenuBar(mbar); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(600,400); setLocationRelativeTo(null); setVisible(true); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable(){ public void run(){ new Example(); } }); } private JFileChooser chooser = new JFileChooser(); private JTextPane textPane = new JTextPane();} 如何知道运行一个运行函数消耗cpu的时间 在Java Swing中,如何做一个可用鼠标拖动改变内部面板大小的JFrame 在一个程序里面 多次使用同一个单例模式的函数 会影响程序性能么 ? 字符串替换问题 求助:在unix系统中使用jxl.jar读取Excel乱码问题? 一个数据源的问题 graphics对象为空? 数据分组 哪里可以下载java sdk for linux??? 请教如何把jbuilder7.0与sql server2000连接起来。 有关流的问题 java 键盘监听的问题
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class Example extends JFrame {
public Example(){
super("Example");
getContentPane().add(new JScrollPane(textPane)); JMenuBar mbar = new JMenuBar();
JMenu insertMenu = new JMenu("Insert");
JMenuItem imageItem = new JMenuItem("Image ...");
insertMenu.add(imageItem);
mbar.add(insertMenu); imageItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int option = chooser.showDialog(Example.this,"Pick a Image");
if (option == JFileChooser.APPROVE_OPTION){
File file = chooser.getSelectedFile();
if (file != null)
textPane.insertIcon(new ImageIcon(file.getPath()));
}
}
}); setJMenuBar(mbar); setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(600,400);
setLocationRelativeTo(null);
setVisible(true);
} public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable(){
public void run(){
new Example();
}
});
} private JFileChooser chooser = new JFileChooser();
private JTextPane textPane = new JTextPane();
}