小编Abh*_*era的帖子

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

我正在编辑.我正在使用Java swing.我已经嵌入JTextAreaJScrollPane.我想把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[] …
Run Code Online (Sandbox Code Playgroud)

java swing jscrollpane jtextarea absolutelayout

2
推荐指数
1
解决办法
3908
查看次数

标签 统计

absolutelayout ×1

java ×1

jscrollpane ×1

jtextarea ×1

swing ×1