zoukankan      html  css  js  c++  java
  • New NetBeans API For Adding Close Button to JTabbedPane

    http://blogs.oracle.com/geertjan/entry/netbeans_apis_add_close_button

    ————————————————————————————————————————————————————————————————————————

    One of the many esoterically ongoing discussions in the Swing world is that of "The Missing Close Button on JTabbedPanes". (To see a selection of these discussions, and various solutions, click here and you'll find yourself in Google, with all the returns for "jtabbedpane close button".) Even in this blog you'll find discussions on this topic. In JDIC Browser on the NetBeans Platform, I discuss various approaches to solving this problem. But... guess what? I was browsing through (the incredibly useful and totally underhighlighted) NetBeans API Changes since Last Release yesterday. And what did I find..? On February 28 of this year, the following was reported on that page: "Added TabbedPane with closeable tabs".

    The summary of the above is as follows:

    Added a factory class for special JTabbedPane that displays a small 'close' button in each tab. When user clicks the close button a PropertyChangeEvent is fired from the tabbed pane.

    How cool is that? The NetBeans APIs come to the rescue, solving a problem in the world of Swing. For details on this issue, see issue 55845 and issue 96754.

    So now each tab in my browser has its own Close button. (Though in some cases you'll need to get a build from after today, because of issue 99691). Below, look at the tab for the two web pages, www.cnn.com and www.guardian.co.uk. Both have a Close button right next to the display name in the tab:

    Behind the scenes, this is how the JTabbedPane is defined:

    browseTabbedPane = new JTabbedPane();
    browseTabbedPane = TabbedPaneFactory.createCloseButtonTabbedPane();
    browseTabbedPane.addPropertyChangeListener( TabbedPaneFactory.PROP_CLOSE, new PropertyChangeListener() {
    public void propertyChange(PropertyChangeEvent evt) {
    JTabbedPane pane = (JTabbedPane)evt.getSource();
    int sel = pane.getSelectedIndex();
    pane.removeTabAt(sel);
    }
    });

    And, by the way, just for context, here's what happens when the JButton is clicked:

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
    WebBrowser wb=new WebBrowser();
    wb.setURL(new URL(txtUrl.getText()));
    wb.setName(txtUrl.getText());
    browseTabbedPane.add(wb);
    } catch(Exception ex) {
    JOptionPane.showMessageDialog(null,ex.getMessage());
    }
    }

    So, in 6.0 there will be a new TabbedPaneFactory class, which will create a special JTabbedPane that displays a small Close button in each tab, exactly as shown above. What happens when the Close button is clicked is up to you. Above, the tab is removed, but anything else could happen there too.

     

  • 相关阅读:
    【宗萨仁波切】研究佛教即是研究自己,而研究自己即是发现无我
    【佩玛.丘卓】在当下那一刻觉醒...
    佩玛·丘卓:人生基本的事实
    佩玛.丘卓的生活智慧——【空船】
    佩玛·丘卓 | 宽恕自己,重新开始
    佩玛·丘卓:修炼平等心
    佩玛•丘卓 :我们需要的皆已具足
    【佩玛丘卓】喂养好狼
    佩玛.丘卓:为事情如实的面目而喜悦
    佩玛·丘卓:精神勇士的口诀
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2193445.html
Copyright © 2011-2022 走看看