簡體   English   中英

如何設置JTextArea大小?

[英]How to set JTextArea size?

我想在JOptionPaneJtextArea設置一個固定大小

public static void main(String[] args) {

        JTextArea headersTxt = new JTextArea();
        for (int i = 0 ; i < 50 ; i ++ ) {
            headersTxt.append("test \n") ;
        }
        JScrollPane scroll = new JScrollPane(headersTxt); 
        scroll.setSize (300,600) ;  // this line silently ignored
        int test = JOptionPane.showConfirmDialog(null,  scroll,"test",  JOptionPane.OK_CANCEL_OPTION) ;

    }

但是,上面的代碼忽略了scroll.setSize (300,600) ;

它工作正常,但大小不固定。 scroll.setSize (300,600) ;有什么問題scroll.setSize (300,600) ;

由於每個系統都可以以不同方式渲染字體,因此應盡可能避免使用像素測量

而是提供要顯示的行和列

JTextArea ta = new JTextArea(5, 20);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM