Java Swing JScrollPane行号故障

我在JScrollPane中有一个简单的JEditorPane,它在左侧显示行号。 除非您将窗口移出屏幕并再次将其拉回,否则它会很有效,当您停止拖动时它会看起来像这样:

在此处输入图像描述

有任何想法吗? 我是否需要监听移动/拖动事件并在某处调用重绘/重新validation?

认为它可能是显而易见的,但这里有一些代码。 我正在使用JSyntaxPane。

public EditorPanel() { this.setLayout(new BorderLayout()); PythonSyntaxKit.initKit(); codeEditor = new JEditorPane(); JScrollPane scrPane = new JScrollPane(codeEditor); Dimension d = new Dimension(710,702); codeEditor.setPreferredSize(d); codeEditor.setContentType("text/python"); codeEditor.setText("Welcome to PhysUtil!"); this.add(scrPane, BorderLayout.CENTER); toolbar = new PhysUtilToolbar(); this.add(toolbar, BorderLayout.PAGE_START); this.repaint(); } //from MainFrame Class... public EditorPanel mainEditor; public MainFrame() { //Someone can figure out how to load the icon...kept throwing an error //ImageIcon icon = new ImageIcon(getClass().getResource("exit.png")); PhysUtilMenuBar menuBar = new PhysUtilMenuBar(); this.mainEditor = new EditorPanel(); menuBar.editorPanel = mainEditor; this.setJMenuBar(menuBar); this.setTitle("PhysUtil"); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.add(mainEditor); Image icon = Toolkit.getDefaultToolkit().getImage("icon.jpg"); this.setIconImage(icon); this.setSize(800, 800); this.setLocation(0, 0); this.setVisible(true); } 

添加一个WindowListener / WindowStateListener / WindowFocusListener …并查看拖动应用程序时触发的事件。 二级屏幕和/或后面。 如果您知道触发的事件,请尝试监听最终事件(无论它将是什么)并使编辑器区域无效(使其变脏)并重新绘制它。 SSCCE也会有所帮助。