Java Swing JScrollPane行号故障 [英] Java Swing JScrollPane line number glitch

查看:117
本文介绍了Java Swing JScrollPane行号故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JScrollPane中有一个简单的JEditorPane,它在左侧显示行号.效果很好,只不过当您将窗口移出屏幕并再次拉回时,当您停止拖动时,它看起来像这样:

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:

有什么想法吗?我是否需要监听移动/拖动事件并在某个地方调用重绘/重新验证?

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

这可能很明显,但是这里有一些代码.我正在使用JSyntaxPane.

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);
    }

推荐答案

添加WindowListener/WindowStateListener/WindowFocusListener ...,并查看如果拖动应用程序将触发哪些事件.到辅助屏幕和/或返回.从那里,如果您知道触发了事件,请尝试侦听最终事件(无论它会是什么),并使您的编辑器区域无效(使其变脏)并重新绘制. SSCCE也将提供帮助.

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.

这篇关于Java Swing JScrollPane行号故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆