1
我正在編寫一個簡單的swing程序,我正在創建一個JFrame並向其中添加一個自定義JComboBox。JComboBox的工具提示位置箭頭按鈕
public class CustomJComboBox<T> extends JComboBox<T> {
public static void main(String[] args) {
new CustomJComboBox<>().initUI();
}
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public Point getToolTipLocation(MouseEvent event) {
System.out.println("getToolTipLocation called");
return super.getToolTipLocation(event);
}
private void initUI() {
JComboBox<String> box = new CustomJComboBox<>();
box.addItem("Item 1");
box.addItem("Item 2");
box.setToolTipText("TooTip");
JFrame frame = new JFrame();
frame.setBounds(0, 0, 300, 300);
frame.add(box);
frame.setVisible(true);
}
}
當我保持鼠標移到組合框被覆蓋getToolTipLocation()方法被調用,但是當我保持鼠標下拉箭頭按鈕,該方法不叫作爲其單獨的JButton。
有沒有辦法控制arrowbutton的工具提示位置呢?