【问题标题】:How to add scrollable JTextArea to jDesktopPane如何将可滚动的 JTextArea 添加到 jDesktopPane
【发布时间】:2009-10-16 11:48:44
【问题描述】:

我尝试了几种意见,但都没有成功。

此方法返回 JTextArea

    private static JTextArea getJArea() {
    if (jArea == null) {
        jArea = new JTextArea();
        jArea.setBounds(new Rectangle(16, 153, 468, 139));
        jArea.setVisible(true);
        jArea.setLineWrap(true);
        jArea.setWrapStyleWord(true);
        jArea.setEditable(false);
        jsp.getViewport().add(jArea);

    }
    return jArea;
}

我在 JDesktopPane 中添加此区域,并使用此代码 sn-p

jDesktopPane.add(getJArea(), null);

这不起作用,我试图创建一个 JScrollPane 并将 JTextArea 分配给他并将其添加到 JDesktopPane,但这也不起作用。

【问题讨论】:

    标签: java swing scroll jdesktoppane


    【解决方案1】:

    您也需要使用JInternalFrameJDesktopPane 应该是 JInternalFrame 对象的父容器。

    JInternalFrame iframe = new JInternalFrame("Title", true, true, true, true);
    iframe.setSize(180, 150);
    iframe.setVisible(true);
    iframe.getContentPane().add(new JScrollPane(new JTextArea("TestText",20,20)));
    JDesktopPane desktop = new JDesktopPane();
    desktop.add(iframe);
    

    然后将JDesktopPane 添加到例如JFrame 你就完成了。

    【讨论】:

    • 是的,基本上就是这样。谢谢。
    • 只需要添加 ((javax.swing.plaf.basic.BasicInternalFrameUI) iframe.getUI()).setNorthPane(null);删除nort标题栏,就是这样。
    猜你喜欢
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多