如何在java swing中实现这个GUI列表

时间:2016-06-17 10:30:12

标签: java swing tree

我想创建一个选项列表,当我的用户将鼠标悬停在按钮鼠标指针上变成手形指针,并在该单词下面显示一条线,我如何在java swing中实现它? 这里有一些我试过的代码

    JButton[] buttons = new JButton[20];
    buttons [0] = new JButton("Option 1");
    buttons [0].setOpaque(true);
    buttons [0].setRolloverEnabled(true);
    buttons [0].setContentAreaFilled(false);
    buttons [0].addMouseListener(new MouseAdapter() {
        @Override
        public void mouseEntered(MouseEvent e) {
            super.mouseEntered(e);
            buttons [0].setFocusPainted(true);
            buttons [0].setFocusable(true);
            buttons [0].setContentAreaFilled(true);
            buttons [0].setCursor(new Cursor(Cursor.HAND_CURSOR));
        }

    });

enter image description here

1 个答案:

答案 0 :(得分:2)

这是一个例子,试试这个

  import javax.swing.JOptionPane;
  public class InputDialogWithDropdownListbox {
  public static void main(String[] a) {
  String[] choices = { "A", "B", "C", "D", "E", "F" };
  String input = (String) JOptionPane.showInputDialog(null, "Choose now...",
   "The Choice of a Lifetime", JOptionPane.QUESTION_MESSAGE, null, // Use
                                                                    //                         default
                                                                    // icon
    choices, // Array of choices
    choices[1]); // Initial choice
   System.out.println(input);
 }
  }
相关问题