實現JComboBox 下拉菜單鼠標懸停提示功能
1
2 JComboBox comboBoxRow= new JComboBox();
3
4 comboBoxRow.setRenderer(new ListCellRenderer() {
5 private ListCellRenderer renderer = comboBoxRow.getRenderer();
6 public Component getListCellRendererComponent(JList list,
7 Object value, int index, boolean isSelected, boolean cellHasFocus) {
8 Component component = renderer.getListCellRendererComponent(
9 list, value, index, isSelected, cellHasFocus);
10 if (component instanceof JLabel) {
11 JLabel label = (JLabel) component;
12 label.setToolTipText(label.getText());
13 }
14 return component;
15 }
16 });
2 JComboBox comboBoxRow= new JComboBox();
3
4 comboBoxRow.setRenderer(new ListCellRenderer() {
5 private ListCellRenderer renderer = comboBoxRow.getRenderer();
6 public Component getListCellRendererComponent(JList list,
7 Object value, int index, boolean isSelected, boolean cellHasFocus) {
8 Component component = renderer.getListCellRendererComponent(
9 list, value, index, isSelected, cellHasFocus);
10 if (component instanceof JLabel) {
11 JLabel label = (JLabel) component;
12 label.setToolTipText(label.getText());
13 }
14 return component;
15 }
16 });
眼鏡蛇
posted on 2014-07-30 16:47 眼鏡蛇 閱讀(462) 評論(0) 編輯 收藏 所屬分類: AWT/SWING/SWT