2012-03-29 29 views
2

JScrollPane内に単純なJEditorPaneがあり、左側に行番号が表示されます。あなたは画面をウィンドウから移動し、再びそれを引くときにドラッグを停止したとき、それはこのように見える以外それは素晴らしい作品:Java Swing JScrollPane行番号グリッチ

enter image description here

任意のアイデア?私は、移動/ドラッグイベントを聞いて、どこかでrepaint/revalidateを呼び出す必要があるでしょうか?

これは明らかなことかもしれませんが、ここにいくつかのコードがあります。私は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); 
    } 
+0

私はTextAreaLineNumberBorderクラスを構築しました.Borderの拡張です。これに興味がありますか? – ControlAltDel

+1

あなたは[SSCCE](http://sscce.org/) – mKorbel

+0

であなたの質問を編集してください2台のモニタのWindowsシステムを使用していますか?それは両方のモニターでこれをしますか? –

答えて

2

のWindowListener /のWindowStateListener /のWindowFocusListener ...を追加して、アプリをドラッグする場合は解雇されたイベントを参照してください。 2次画面および/または背面に表示する。そこからイベントが発生したことが分かっている場合は、最後のイベント(何があっても構わない)でリッスンし、エディタの領域を無効にして(汚れさせる)、それを再描画します。 SSCCEも助けになるでしょう。

+1

これは私が受け入れた解決策でしたが、WindowListenerではありませんでした。私は、MoveイベントをチェックするためにComponentListenerが必要でした。私はメインエディタJPanelで再描画を呼び、すべてがうまくいきます。 – Josh

+0

@Josh WindowListenerの後に小さな「...」ワイルドカードが表示されるようになりました(嬉しいですが、それでも助けてくれました! – lzdt