我正在尝试在java swing中创建自定义查看器,我已经设法在我的iFrame上显示文本数据,但问题在于文本卷是; arge因为滚动条出现在框架上但不起作用....请让我知道可以做什么......代码......
公共类DocumentViewer扩展了JFrame {
static JEditorPane je = new JEditorPane();
static JTextArea textArea = new JTextArea();
StringBuffer outputBuff = new StringBuffer();
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
DocumentViewer frame = new DocumentViewer();
JInternalFrame iFrame = new JInternalFrame("Document",false, true, false, false);
JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
iFrame.getContentPane().add(textArea, BorderLayout.CENTER);
iFrame.setVisible(true);
iFrame.validate();
frame.getContentPane().add(iFrame, BorderLayout.CENTER);
frame.setVisible(true);
frame.validate();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public DocumentViewer() {
outputBuff = readFile();
System.out.println("::::output" + outputBuff);
textArea.setText(outputBuff.toString());
textArea.requestFocus();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 350, 350);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
public StringBuffer readFile(){
StringBuffer sb = new StringBuffer();
try{
//text[start]
BufferedReader buf = new BufferedReader(new FileReader("C:\\Users\\azhar.memon\\Desktop\\test.txt"));
String readLine = buf.readLine();
while(readLine != null){
sb.append(readLine + " ").append(System.getProperty("line.separator"));
readLine = buf.readLine();
}
buf.close();
System.out.println(":::" + sb);
//text[end]
}catch(Exception e){
e.printStackTrace();
}
return sb;
}
}