Ejemplo n.º 1
0
 @Override
 public void mouseMoved(MouseEvent event) {
   JTextPane textPane = (JTextPane) event.getSource();
   Point point = new Point(event.getX(), event.getY());
   int position = textPane.viewToModel(point);
   DefaultStyledDocument document = (DefaultStyledDocument) textPane.getDocument();
   Element element = document.getCharacterElement(position);
   AttributeSet attributeSet = element.getAttributes();
   String sLink = (String) attributeSet.getAttribute("link");
   if (sLink != null) {
     textPane.setCursor(handCursor);
   } else {
     textPane.setCursor(textCursor);
   }
 }
  public AgentTimeJTextPane() throws UnsupportedEncodingException {
    // 初始化所有模块
    frame = new JFrame("Maximo监控程序");
    textPane = new JTextPane();
    textPane.setCursor(new Cursor(Cursor.TEXT_CURSOR));
    textPane.setText("java版本为:" + System.getProperty("java.version") + "\n换行");
    // 设置主框架的布局
    Container c = frame.getContentPane();
    // c.setLayout(new BorderLayout())

    JScrollPane jsp = new JScrollPane(textPane); // 新建一个滚动条界面,将文本框传入
    c.add(jsp, BorderLayout.CENTER);

    /*
     *  文本框二
     */
    textPane2 = new JTextPane();
    textPane2.setCursor(new Cursor(Cursor.TEXT_CURSOR));
    JScrollPane jsp2 = new JScrollPane(textPane2); // 新建一个滚动条界面,将文本框传入
    c.add(jsp2, BorderLayout.SOUTH);

    /*
     * 增加标签
     */
    Label label = new Label("java Version:" + System.getProperty("java.version"));
    c.add(label, BorderLayout.NORTH);

    // 利用无名内隐类,增加窗口事件
    frame.addWindowListener(
        new WindowAdapter() {
          public void WindowClosing(WindowEvent e) {
            // 释放资源,退出程序
            frame.dispose();
            System.exit(0);
          }
        });

    frame.setSize(700, 500);
    // 隐藏frame的标题栏,此功暂时关闭,以方便使用window事件
    // setUndecorated(true);
    frame.setLocation(200, 150);
    frame.show();
  }
Ejemplo n.º 3
0
 public GithubLoginPanel(final GithubLoginDialog dialog) {
   DocumentListener listener =
       new DocumentAdapter() {
         @Override
         protected void textChanged(DocumentEvent e) {
           dialog.clearErrors();
         }
       };
   myLoginTextField.getDocument().addDocumentListener(listener);
   myPasswordField.getDocument().addDocumentListener(listener);
   mySignupTextField.setText(
       "<html>Do not have an account at github.com? <a href=\"https://github.com\">Sign up</a>.</html>");
   mySignupTextField.setMargin(new Insets(5, 0, 0, 0));
   mySignupTextField.addHyperlinkListener(
       new HyperlinkAdapter() {
         @Override
         protected void hyperlinkActivated(final HyperlinkEvent e) {
           BrowserUtil.browse(e.getURL());
         }
       });
   mySignupTextField.setBackground(UIUtil.TRANSPARENT_COLOR);
   mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR));
 }