我将在同一区域显示 deneme2.txt 和 deneme1.txt。但只有我有 deneme1.txt 的结果。我想在左侧显示 deneme2.txt。但我做不到。
你能帮我吗?
我在分享时遇到问题,抱歉代码分享。
import java.awt.Container;
import java.awt.GridLayout;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class TextAreaSample
{
public static void main(String args[])
{
String title = (args.length == 0 ? "TextArea Example" : args[0]);
JFrame frame = new JFrame(title);
Container content = frame.getContentPane();
content.setLayout(new GridLayout(0, 2));
JTextArea leftTextArea = new JTextArea();
JScrollPane rightPane = new JScrollPane(leftTextArea);
try
{
leftTextArea.read(new FileReader("C:\\Denemeler\\deneme2.txt"), null);
} catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
content.add(leftTextArea);
JTextArea rightTextArea = new JTextArea()
{
public boolean isManagingFocus()
{
return false;
}
};
JScrollPane leftPane1 = new JScrollPane(rightTextArea);
JScrollPane rightPane1 = new JScrollPane(leftTextArea);
try
{
leftTextArea.read(new FileReader("C:\\Denemeler\\deneme1.txt"), null);
} catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
content.add(leftPane1);
content.add(rightPane1);
frame.setSize(250, 150);
frame.setVisible(true);
}
}