2

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 screen and pull it back again, it looks the this when you stop dragging:

enter image description here

any ideas? Should I need to be listening for a move/drag event and calling repaint/revalidate somewhere?

Thought it might be something obvious, but here is some code. I am using the 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);
    }
Josh
  • 451
  • 8
  • 22
  • Back in the day I built a TextAreaLineNumberBorder class, an extension of Border. Would you have any interest in this? – ControlAltDel Mar 29 '12 at 17:24
  • 1
    no idea, please edit your question with a [SSCCE](http://sscce.org/) – mKorbel Mar 29 '12 at 17:32
  • Are you on a two monitor Windows system? Does it do this on both monitors? – Steve Kuo Mar 29 '12 at 17:43
  • Your JRE version is ? Since if it's 1.7, than do try to run your program on 1.6, there are some bugs too in 1.7, without a good example of the code you are using, it's hard to say anything :-) – nIcE cOw Mar 29 '12 at 17:58
  • adding some code. sorry about that. I am on a two window system, but this also happens on my laptop too as well as other user's systems. – Josh Mar 29 '12 at 20:51

1 Answers1

2

Add a WindowListener/WindowStateListener/WindowFocusListener... and see which events are getting fired if you drag your app. to secondary screen and/or back. From there if you know the events triggered try to listen on final event (whatever it will be) and invalidate your editor area (make it dirty) and repaint it. SSCCE would help too.

lzdt
  • 489
  • 1
  • 6
  • 17
  • 1
    This was the solution I accepted although it was not a WindowListener I needed a ComponentListener to check for a move event. I called repaint on my mainEditor JPanel and all is well. – Josh Mar 29 '12 at 23:08
  • @Josh I hopped you would see the small "..." wildcard after WindowListener (: Glad it helped nevertheless! – lzdt Mar 30 '12 at 10:27