簡體   English   中英

在JEditorPane中添加滾動條,setLayout為null

[英]Add Scroll bar in JEditorPane, setLayout null

我無法在EditorPane上添加滾動條。

private JEditorPane editorPane;
private JScrollPane scrollpane;

容器 :

Container c = getContentPane();
    c.setLayout(null);
    setBounds(100, 100, 450, 300);

    editorPane = new JEditorPane();
    editorPane.setBounds(0, 54, 434, 208);

    scrollpane = new JScrollPane(editorPane);
    scrollpane.setPreferredSize(new Dimension(350, 110));

    c.add(scrollpane);

.. ..什么都沒加

您在這里開槍射擊自己:

editorPane.setBounds(0, 54, 434, 208);

通過設置editorPane的絕對大小,可以防止它在需要時擴展,從而避免顯示JScrollBars。

解決方案:不要這樣做。 是的,避免使用空布局。 當您發現時,他們會咬您。 使用CSS設置寬度

 getContentPane().setLayout(null); 

這意味着“我該死在別人的幫助下,因為我比其他人都知道如何布局GUI!”

這就是您的位置。

我建議閱讀這些教程,並學習如何使用LayoutManagers構建GUI。

暫無
暫無

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

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