Example usage for javax.swing JTabbedPane getBoundsAt

List of usage examples for javax.swing JTabbedPane getBoundsAt

Introduction

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

Prototype

public Rectangle getBoundsAt(int index) 

Source Link

Document

Returns the tab bounds at index.

Usage

From source file:Main.java

@Override
public void paint(Graphics g, JComponent c) {
    super.paint(g, c);
    if (c instanceof JLayer == false) {
        return;/*  w w  w .  ja  v a  2  s .c  om*/
    }
    JLayer jlayer = (JLayer) c;
    JTabbedPane tabPane = (JTabbedPane) jlayer.getView();
    for (int i = 0; i < tabPane.getTabCount(); i++) {
        Rectangle rect = tabPane.getBoundsAt(i);
        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);
        button.setForeground(r.contains(pt) ? Color.RED : Color.BLACK);
        SwingUtilities.paintComponent(g, button, p, r);
    }
}

From source file:Main.java

@Override
protected void processMouseMotionEvent(MouseEvent e, JLayer<? extends JTabbedPane> l) {
    pt.setLocation(e.getPoint());/*from   ww  w .ja va2s  . c  om*/
    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 ww .  java  2  s  . co  m
    }
    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();
}