英文:
Strange swing border artifact
问题
以下是翻译好的代码部分:
public class TestPanel extends JPanel {
private static void createAndShowGUI() {
JFrame myFrame = new JFrame("");
myFrame.setBounds(new Rectangle(100, 100, 240, 180));
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel box = new JPanel(null);
box.setBackground(Color.BLUE);
JPanel left = new JPanel();
left.setOpaque(false);
JPanel right = new JPanel();
right.setOpaque(false);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
splitPane.setResizeWeight(0.5);
splitPane.setOpaque(false);
box.setLayout(new BorderLayout());
box.setBorder(new EmptyBorder(10, 10, 10, 10));
box.add(splitPane);
myFrame.getContentPane().add(box, BorderLayout.CENTER);
myFrame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(TestPanel::createAndShowGUI);
}
}
它产生以下结果:
如果您仔细看左下角,您可能会注意到奇怪的边框失真:
有人知道出了什么问题吗?
在 macOS、jdk1.8.0_251 上进行了测试。
英文:
Here is my simplified code example:
public class TestPanel extends JPanel {
private static void createAndShowGUI() {
JFrame myFrame = new JFrame("");
myFrame.setBounds(new Rectangle(100, 100, 240, 180));
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel box = new JPanel(null);
box.setBackground(Color.BLUE);
JPanel left = new JPanel();
left.setOpaque(false);
JPanel right = new JPanel();
right.setOpaque(false);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
splitPane.setResizeWeight(0.5);
splitPane.setOpaque(false);
box.setLayout(new BorderLayout());
box.setBorder(new EmptyBorder(10, 10, 10, 10));
box.add(splitPane);
myFrame.getContentPane().add(box, BorderLayout.CENTER);
myFrame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(TestPanel::createAndShowGUI);
}
}
It produces following result:
If you look closely at the bottom left corner, you may notice strange border distortion:
Does anyone have an idea what is wrong?
Tested on macos, jdk1.8.0_251
答案1
得分: 1
Sure, here's the translated content:
似乎这是您本地的问题。我无法看到这个工件。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论