我试图将JScrollPane添加到我的JTextArea,它不起作用.有人能告诉我有什么问题吗?我想只有横向的
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class Program extends JFrame{
JButton button1, button2;
JTextArea textArea1;
JScrollPane scroller;
public static String directory, nameOfFile, finalPath;
public static void main(String[] args){
new Program();
}
public Program(){
this.setSize(500,500);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setTitle("swinging");
JPanel thePanel = new JPanel();
thePanel.setLayout(null);
thePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
button1 = new JButton("Wybierz plik:");
button2 = new JButton("Dodaj");
final JTextField text = new JTextField(24);
textArea1 = new JTextArea();
textArea1.setEditable(true);
textArea1.setLineWrap(true);
textArea1.setPreferredSize(new Dimension(490,200));
scroller = new JScrollPane(textArea1);
scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
thePanel.add(button1);
thePanel.add(text); …Run Code Online (Sandbox Code Playgroud)