如何才能简单导入文档? textpane.setPage(ClassLoader.getSystemResource("aaa.txt"));aaa.txt放在classes目录下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你的fileDialog换成现成的JFileChooser不好吗?textpane.setPage(fileDialog.getSelectedFile().toURL()); 老大:只能显示 *.java.不能显示*.txt.....怎么办??是不是用JTextPane不好?要不换个JTestField 或是其他的试一试.似乎一定要用到BufferedReader之类的东东......把你的fileDialog换成现成的JFileChooser不好吗?请告知怎么换........请给出完整源程序好吗,一定重谢........目的:用java写一个类似于windows自带的记事本.............. 写了一个,你看看,另外jdk/demo/jfc下有一个notebook的例子,可以参考import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;public class SplitTest extends JFrame { JScrollPane sp = new JScrollPane(); JEditorPane tp = new JEditorPane(); JButton btn = new JButton("open"); public SplitTest() { this.setSize(400, 300); this.getContentPane().add(sp, BorderLayout.CENTER); this.getContentPane().add(btn, BorderLayout.SOUTH); sp.getViewport().add(tp, null); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFile(); } }); } public void openFile() { JFileChooser ch = new JFileChooser(); try { if (ch.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { //判断按下的是否是Open按钮 File file = ch.getSelectedFile(); if (file != null && !file.isDirectory()) //判断是否选中文件及选中文件是否是文件夹 tp.setPage(file.toURL()); } } catch(Exception ex) {} } public static void main(String[] args) { SplitTest frame = new SplitTest(); frame.setVisible(true); }} 关于java socket 接受c语言发送的数据包问题 出学者问题 请大家帮助 自定义标签有什么用? bufferedreader.read()干吗用的 还未入门者请教 大神写swing都是事先布置UI么,用的什么软件 5.6E-4是什么数据格式啊? 在2000下如何配置java环境? 怎样把对象写到SQL Server数据库中(各位大侠帮忙) 如何将string类型转换成date类型?急 关于获得tree的路径的问题 drawRect()的小问题!
似乎一定要用到BufferedReader之类的东东......
把你的fileDialog换成现成的JFileChooser不好吗?请告知怎么换........
请给出完整源程序好吗,一定重谢........
目的:用java写一个类似于windows自带的记事本..............
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;public class SplitTest extends JFrame {
JScrollPane sp = new JScrollPane();
JEditorPane tp = new JEditorPane();
JButton btn = new JButton("open");
public SplitTest() {
this.setSize(400, 300);
this.getContentPane().add(sp, BorderLayout.CENTER);
this.getContentPane().add(btn, BorderLayout.SOUTH);
sp.getViewport().add(tp, null);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openFile();
}
});
}
public void openFile() {
JFileChooser ch = new JFileChooser();
try {
if (ch.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { //判断按下的是否是Open按钮
File file = ch.getSelectedFile();
if (file != null && !file.isDirectory()) //判断是否选中文件及选中文件是否是文件夹
tp.setPage(file.toURL());
}
} catch(Exception ex) {}
} public static void main(String[] args) {
SplitTest frame = new SplitTest();
frame.setVisible(true);
}
}