问题描述
一种非常简单的文本编辑器。
现在的问题是框架周围有一个非常细的白色边框。
如果文本窗格的颜色为白色,这没问题,但如果我将文本窗格设为深色,则白色轮廓看起来很糟糕。
这是我的代码:
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 ));
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,但它删除了标题栏而不是大纲。
这是我所说的白色轮廓:
有人可以帮忙解决这个问题吗?
解决方法
这是由于滚动窗格的默认边框造成的。我们可以通过给它设置一个空边框来摆脱它。
这是更新的代码:
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 ));
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);
}
}
,
在 JFrames 中添加另一个边框并为其定义颜色,我希望它会起作用