Ich habe einen Code für die Bildlaufleiste hinzugefügt, den ich von Fragen erhalten habe, die von anderen Benutzern auf stackoverflow gestellt wurden, aber ich bekomme keine Bildlaufleiste zu meiner JTextArea hinzugefügt. Ich möchte scrollbar JTextArea Bereich2 in f2 Rahmen hinzufügen.Bildlaufleiste wird nicht angezeigt
import javax.swing.*;
import java.io.*;
import java.awt.event.*;
public class TextAreaExample implements ActionListener {
JFrame f1 = new JFrame("INPUT WINDOW");
JFrame f2 = new JFrame("FILE DATA OUTPUT");
JTextArea area1;
JTextArea area2;
JButton b;
TextAreaExample() {
area1 = new JTextArea();
area2 = new JTextArea();
JScrollPane scroll = new JScrollPane (area2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
b = new JButton("click Me");
b.setBounds(100, 95, 80, 30);
f1.add(b);
area1.setBounds(10, 30, 200, 60);
area2.setBounds(5, 5, 480, 480);
f1.add(area1);
f2.add(area2);
f2.add(scroll);
f1.setSize(300,140);
f2.setSize(510, 510);
f1.setLayout(null);
f2.setLayout(null);
f1.setVisible(true);
f2.setVisible(true);
b.addActionListener(this);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b) {
String s1 = area1.getText();
String s2 = "";
try {
FileInputStream fin = new FileInputStream(s1);
BufferedInputStream bin = new BufferedInputStream(fin);
int i;
while((i = bin.read()) != -1) {
s2 = s2 + (char)i;
}
bin.close();
fin.close();
}catch(Exception a) {
System.out.println(a);
}
area2.setText(s2);
}
}
public static void main(String args[]) {
new TextAreaExample();
}
}
Ok, jetzt funktioniert es, wie ich wollte, danke. –