Exemplo n.º 1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   String command = e.getActionCommand();
   if (ValueWidget.isInteger(command)) {
     int selectedIndex = Integer.parseInt(command);
     tabbedPane.setSelectedIndex(selectedIndex);
     //			autoTestPanel.searchSuccess(selectedIndex);
   } else {
     ToastMessage.toast("已取消", 2000, Color.RED);
   }
 }
Exemplo n.º 2
0
  public ToastMessage(
      String toastString, int time, Color bgColor, final ToastCallback toastCallback) {
    this.miliseconds = time;
    setUndecorated(true);
    getContentPane().setLayout(new BorderLayout(0, 0));

    JPanel panel = new JPanel();
    if (ValueWidget.isNullOrEmpty(bgColor)) {
      bgColor = Color.blue;
    }
    panel.setBackground(bgColor);
    panel.setBorder(new LineBorder(Color.LIGHT_GRAY, 2));
    getContentPane().add(panel, BorderLayout.CENTER);

    JLabel toastLabel = new JLabel();
    toastLabel.setText(toastString);
    toastLabel.setFont(new Font("Dialog", Font.BOLD, 12));
    toastLabel.setForeground(Color.WHITE);

    setSize(toastLabel.getPreferredSize().width + 20, 31);

    setAlwaysOnTop(true);
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int y = dim.height / 2 - getSize().height / 2;
    int half = y / 2;
    setLocation(dim.width / 2 - getSize().width / 2, y + half);
    panel.add(toastLabel);
    setVisible(false);

    new Thread() {
      public void run() {
        try {
          Thread.sleep(miliseconds);
          dispose();
          // 回调
          if (!ValueWidget.isNullOrEmpty(toastCallback)) {
            toastCallback.callback();
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }.start();
  }