Example usage for javax.swing JTabbedPane indexAtLocation

List of usage examples for javax.swing JTabbedPane indexAtLocation

Introduction

In this page you can find the example usage for javax.swing JTabbedPane indexAtLocation.

Prototype

public int indexAtLocation(int x, int y) 

Source Link

Document

Returns the tab index corresponding to the tab whose bounds intersect the specified location.

Usage

From source file:Main.java

@Override
protected void processMouseMotionEvent(MouseEvent e, JLayer<? extends JTabbedPane> l) {
    pt.setLocation(e.getPoint());//from w w w  . j  a va2 s  . c o  m
    JTabbedPane tabbedPane = (JTabbedPane) l.getView();
    int index = tabbedPane.indexAtLocation(pt.x, pt.y);
    if (index >= 0) {
        tabbedPane.repaint(tabbedPane.getBoundsAt(index));
    } else {
        tabbedPane.repaint();
    }
}

From source file:Main.java

@Override
protected void processMouseEvent(MouseEvent e, JLayer<? extends JTabbedPane> l) {
    if (e.getID() != MouseEvent.MOUSE_CLICKED) {
        return;/*from   w  w  w .  ja  v a2 s  .  c  om*/
    }
    pt.setLocation(e.getPoint());
    JTabbedPane tabbedPane = (JTabbedPane) l.getView();
    int index = tabbedPane.indexAtLocation(pt.x, pt.y);
    if (index >= 0) {
        Rectangle rect = tabbedPane.getBoundsAt(index);
        Dimension d = button.getPreferredSize();
        int x = rect.x + rect.width - d.width - 2;
        int y = rect.y + (rect.height - d.height) / 2;
        Rectangle r = new Rectangle(x, y, d.width, d.height);
        if (r.contains(pt)) {
            tabbedPane.removeTabAt(index);
        }
    }
    l.getView().repaint();
}

From source file:ome.formats.importer.gui.GuiImporter.java

/**
 * Check if the history table is enabled, disabling the history tab 
 * if it is not./*from  ww  w .  j  ava 2  s  .  c o m*/
 */
void checkHistoryEnable() {
    tPane.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {

            JTabbedPane pane = (JTabbedPane) e.getSource();

            boolean userDisabled = config.getUserDisableHistory() | config.getStaticDisableHistory();

            if (pane.indexAtLocation(e.getX(), e.getY()) == historyTabIndex
                    && getHistoryTable().db.historyEnabled == false) {
                if (HistoryDB.alertOnce == false && !userDisabled) {
                    JOptionPane.showMessageDialog(null,
                            "For some reason we are not able to connect to the remote\n"
                                    + "history service (this most likely means the server does\n"
                                    + "not have this feature installed). In the meantime, you will\n"
                                    + "still be able to use the importer, however the history tab's\n"
                                    + "functionality will not be enabled.",
                            "Warning", JOptionPane.ERROR_MESSAGE);
                    HistoryDB.alertOnce = true;
                }
            }
        }
    });
}