List of usage examples for javax.swing JTabbedPane getLocationOnScreen
public Point getLocationOnScreen()
From source file:Main.java
public static void main(String[] args) { final JTabbedPane jTabbedPane = new JTabbedPane(); jTabbedPane.addTab("Red", new JLabel("Roses")); jTabbedPane.addTab("Blue", new JLabel("Skies")); jTabbedPane.addTab("Green", new JLabel("Grass")); for (int i = 0; i < jTabbedPane.getTabCount(); i++) { final JLabel tabComponent = new JLabel(jTabbedPane.getTitleAt(i)); tabComponent.addMouseMotionListener(new MouseMotionAdapter() { @Override//from w w w . j a va2s.co m public void mouseDragged(MouseEvent e) { System.out.println("tabComponent dragging"); } }); tabComponent.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int x = tabComponent.getLocationOnScreen().x - jTabbedPane.getLocationOnScreen().x; int y = tabComponent.getLocationOnScreen().y - jTabbedPane.getLocationOnScreen().y; MouseEvent me = new MouseEvent((JLabel) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), x, y, e.getLocationOnScreen().x, e.getLocationOnScreen().y, e.getClickCount(), e.isPopupTrigger(), e.getButton()); jTabbedPane.getMouseListeners()[0].mousePressed(me); System.out.println("tabComponent mousePressed e=" + e); } }); jTabbedPane.setTabComponentAt(i, tabComponent); } JFrame jFrame = new JFrame(); jFrame.add(jTabbedPane); jFrame.setSize(400, 500); jFrame.setVisible(true); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }