Java Swing JScrollPane Error

I have a simple JEditorPane inside a JScrollPane that displays line numbers on the left side. It works great, except when you move the window off the screen and drag it again, it looks like when you stop dragging:

enter image description here

any ideas? Should I listen for the move / drag event and trigger a redraw / revalidate somewhere?

Thought it might be something obvious, but here is some code. I am using 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); } 
+2
source share
1 answer

Add WindowListener / WindowStateListener / WindowFocusListener ... and see what events are fired when you drag and drop your application. to the secondary screen and / or vice versa. From there, if you know that the triggered events try to listen to the final event (no matter what it will be), and invalidate the editor area (make it dirty) and redraw it. SSCCE will help too.

+2
source

Source: https://habr.com/ru/post/969899/


All Articles