繁体   English   中英

Nimbus JTextArea默认边框

[英]Nimbus JTextArea default border

因此,我的程序中有一个使用Nimbus LAF的JTextArea。 由于某些功能问题,我需要将其交换为JTextPane。

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

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

如何获得默认的JTextBoreder到JTextPane?

我想您正在寻找:

UIManager.getDefaults().getBorder("TextArea.border");

有它雨云手,我与这些画家*个月后,我取得胜利。

请注意,所使用的密钥可以在操作系统之间进行更改(因此不能保证在那里,但是确实可以在我的系统上运行)。 只要您具有JTextArea边框的有效键,就可以将其传输到JTextPane

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);
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM