首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nimbus JTextArea默认边框

Nimbus JTextArea默认边框
EN

Stack Overflow用户
提问于 2012-10-12 00:32:22
回答 2查看 1.9K关注 0票数 0

因此,我的程序中有一个使用Nimbus LAF的JTextArea。因为一些功能问题,我需要把它换成JTextPane。

但是,默认情况下,JTextArea具有绘制的边框。JTextPane不需要。我不知道哪个是JTextArea的默认边框将其设置为JTextPane。

我尝试使用getBorder(),但只返回"javax.swing.plaf.synth.SynthBorder@455e3f91“

如何获取JTextPane的默认JTextBoreder?

EN

回答 2

Stack Overflow用户

发布于 2012-10-12 00:39:42

我猜你正在寻找这个:

代码语言:javascript
复制
UIManager.getDefaults().getBorder("TextArea.border");
票数 2
EN

Stack Overflow用户

发布于 2012-10-12 04:18:23

在让Nimbus用这些*绘图器把它交给我几个月后,我胜利了。

请注意,使用的密钥可以在不同的操作系统之间改变(所以不能保证,但它在我的操作系统上确实有效)。只要你有一个有效的JTextArea边界密钥,你就可以把它转移到你的JTextPane上。

代码语言:javascript
复制
import java.awt.Insets;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;


public class NimbusBorderPainting extends Box{

    public NimbusBorderPainting(){
        super(BoxLayout.Y_AXIS);
        try {
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (UnsupportedLookAndFeelException e2) {
            e2.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        //Retrieve the TextArea painter from the defaults 
        Object o = UIManager.get("TextArea[Enabled+NotInScrollPane].borderPainter");        

        //Transfer the Painter to a TextPane key
        UIDefaults paneDefaults = new UIDefaults();
        paneDefaults.put("TextPane.borderPainter",o);

        JTextPane pane = new JTextPane();
        pane.setMargin(new Insets(10, 10, 10, 10));

        //Apply the new UI to your text pane
        pane.putClientProperty("Nimbus.Overrides",paneDefaults);
        pane.putClientProperty("Nimbus.Overrides.InheritDefaults",false);
        pane.setText("Lots of Text\nWell, as much as I'm willing to type\n");
        add(pane);

    }

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(new NimbusBorderPainting());
        frame.validate();
        frame.pack();
        frame.setVisible(true);
    }

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12844337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档