有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

未设置jscrollpane中jtextarea的java位置和大小

我在编辑部工作。我正在使用JavaSwing。我用JScrollPane嵌入了一个JTextArea。我想把特定大小的jtextarea放在JScrollPane的中间。为此,我使用了setLocation函数。但这不管用

public class ScrollPaneTest extends JFrame {
private Container myCP;
private JTextArea resultsTA;
private JScrollPane scrollPane;
private  JPanel jpanel;

public ScrollPaneTest() {
resultsTA = new JTextArea(50,50);
resultsTA.setLocation(100,100);
jpanel=new JPanel(new BorderLayout());
jpanel.add(resultsTA,BorderLayout.CENTER);

scrollPane = new JScrollPane(jpanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(800, 800));
scrollPane.setBounds(0, 0, 800, 800);

setSize(800, 800);
setLocation(0, 0);
myCP = this.getContentPane();
myCP.setLayout(new BorderLayout());
myCP.add(scrollPane);
setVisible(true);
addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
 });
}
public static void main(String[] args) {
     new ScrollPaneTest();
     }
}

共 (0) 个答案