删除白色轮廓 JFrame

时间:2021-04-09 09:37:56

标签: java swing user-interface jframe jtextpane

我有一个带有 JTextPane 的 JFrame。

一种非常简单的文本编辑器。

现在的问题是框架周围有一个非常细的白色边框。

如果文本窗格的颜色为白色,这没问题,但如果我将文本窗格设为深色,则白色轮廓看起来很糟糕。

这是我的代码:

import javax.swing.*;
import java.awt.*;
public class Try{
    public static void main(String[] args) {
        JFrame frame = new JFrame("Try");
        frame.setLayout(new GridLayout(1, 1, 0 ,0 ));
        JTextPane tpane = new JTextPane();
        tpane.setBackground(Color.BLACK);
        tpane.setForeground(Color.WHITE);
        JScrollPane scp = new JScrollPane(tpane);
        frame.add(scp);
        frame.setSize(900, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

我尝试过 setUndecorated,但它删除了标题栏而不是大纲。

这是我所说的白色轮廓:

Screenshot

有人可以帮忙解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

这是由于滚动窗格的默认边框造成的。我们可以通过给它设置一个空边框来摆脱它。

这是更新的代码:

import javax.swing.*;
import java.awt.*;
public class Try{
    public static void main(String[] args) {
        JFrame frame = new JFrame("Try");
        frame.setLayout(new GridLayout(1, 1, 0 ,0 ));
        JTextPane tpane = new JTextPane();
        tpane.setBackground(Color.BLACK);
        tpane.setForeground(Color.WHITE);
        JScrollPane scp = new JScrollPane(tpane);
        scp.setBorder(BorderFactory.createEmptyBorder());
        frame.add(scp);
        frame.setSize(900, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

答案 1 :(得分:-2)

在 JFrames 中添加另一个边框并为其定义颜色,我希望它会起作用

相关问题