2012-10-22 2 views
1

java.net에서 BallonTip을 보았습니다. 사용자가 표 셀을 클릭 할 때 표시되도록 내 응용 프로그램에 통합하려고했습니다. 표 셀을 클릭하면 BalloonTip이 의도 한대로 표시되지만 현재 뷰포트 밖으로 스크롤하면 BalloonTip이 표시되지 않고 다른 셀을 클릭 할 수 있습니다. 표를 스크롤하면 BallonTip이 다시 표시됩니다. 나는 테이블의 셀을 클릭 한 후java.net BalloonTip이 보이지 않습니다.

나는 BalloonTip을 강제 할 방법
import java.awt.Color; 
import java.awt.Dimension; 

import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JLayeredPane; 
import javax.swing.JPanel; 
import javax.swing.JScrollPane; 
import javax.swing.JTable; 
import javax.swing.event.ListSelectionEvent; 
import javax.swing.event.ListSelectionListener; 

import net.java.balloontip.BalloonTip; 
import net.java.balloontip.TablecellBalloonTip; 
import net.java.balloontip.styles.EdgedBalloonStyle; 

public class TableTest2 extends JFrame { 

static final int LENGTH = 40; 
TablecellBalloonTip tip; 
JTable mainTable; 
JPanel main; 
JLayeredPane layeredPane; 
JScrollPane mainScroll; 

TableTest2() { 
    mainTable = new JTable(LENGTH, LENGTH); 
    CustomListSelectionListener clsl = new CustomListSelectionListener(mainTable); 
    mainTable.getColumnModel().getSelectionModel().addListSelectionListener(clsl); 
    mainTable.getSelectionModel().addListSelectionListener(clsl); 
    mainTable.setTableHeader(null); 
    mainTable.setColumnSelectionAllowed(true); 
    mainScroll = new JScrollPane(mainTable); 
    add(mainScroll); 

    tip = new TablecellBalloonTip(mainTable, new JLabel("Hello World!"), -1, -1, new EdgedBalloonStyle(Color.WHITE, 
      Color.BLUE), BalloonTip.Orientation.LEFT_ABOVE, BalloonTip.AttachLocation.ALIGNED, 5, 5, false); 

    setPreferredSize(new Dimension(500, 400)); 
    setVisible(true); 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    pack(); 

} 

public static void main(String[] args) { 
    new TableTest2(); 
} 

protected class CustomListSelectionListener implements ListSelectionListener { 
    private int row, column, lead, anchor; 
    private JTable table; 

    public CustomListSelectionListener(JTable table) { 
     this.table = table; 
    } 

    @Override 
    public void valueChanged(ListSelectionEvent evt) { 
     if (evt.getSource() == table.getSelectionModel() && table.getRowSelectionAllowed()) { 
      // row selection changed 
      row = table.getSelectedRow(); 
      column = table.getSelectedColumn(); 
      tip.setCellPosition(row, column); 
      tip.refreshLocation(); 
     } else if (evt.getSource() == table.getColumnModel().getSelectionModel() 
       && table.getColumnSelectionAllowed()) { 
      // column selection changed 
      lead = table.getColumnModel().getSelectionModel().getLeadSelectionIndex(); 
      anchor = table.getColumnModel().getSelectionModel().getAnchorSelectionIndex(); 
      if (lead <= anchor) { 
       column = anchor; 
      } else { 
       column = lead; 
      } 
      row = table.getSelectedRow(); 
      tip.setCellPosition(row, column); 
      tip.refreshLocation(); 
     } 
    } 
} 
} 

이 표시 될 : 여기

은 예입니다? 나는 스크롤 이벤트를 듣고 BallonTip의 그림을 관리하는 청취자가 있다고 생각하지만, 나는 그것이 하나라는 단서가 없다.

안부

답변

1

to this mailing list에 따르면 HTZ는 BallonTip 버전 1.2.1의 버그가 있었다. 이제 버전 1.2.3에서는이 문제가 해결되었습니다.

+0

최신 버전을 다운로드 할 수있는 공식적인 장소가 있습니까? 메일 링리스트의 링크가 드롭 박스를 가리 킵니다 ... 프로젝트 페이지가 아닙니다. –

+0

[프로젝트 페이지] (https://java.net/projects/balloontip)에는 1.2.1 버전 만 있습니다. Dropbox 링크는 아직 1.2.3 버전의 유일한 소스 인 것 같습니다. – htz

+0

이 링크는 구성 요소 작성자가 메일 링리스트에 게시했습니다. 따라서 신뢰할 수있는 출처로 생각할 수있는 것 같습니다. =) –