我試圖在JTextArea中添加滾動條滾動條,但沒有在textarea的顯示..的Java Swing JTextArea的滾動條不顯示內部
這裏是我的代碼,
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame("MySql Console");
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
panel.setLayout(null);
JTextArea txtQuery = new JTextArea();
txtQuery.setBounds(10, 10, 365, 45);
JScrollPane scroll = new JScrollPane (txtQuery,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//scroll.setPreferredSize(new Dimension(100, 50));
panel.add(scroll);
panel.add(txtQuery);
frame.setVisible(true);
}
}
試圖從網上一些替代品,但還是行不通。