I created a custom jTabbedPane class that extends BasicTabbedPaneUI and successfully created my desired jTabbedPane , but now the problem is that I can set the Hand pointer for each tab in my custom jTabbedPane
I tried to set the cursor using this
tabbedPane.setUI(new CustomMainMenuTabs()); tabbedPane.setCursor(new Cursor((Cursor.HAND_CURSOR)));
this sets the cursor for the whole jTabbedPane, but I want to set the cursor when the mouse is over only any tab.
How to set tabs cursor in jTabbedPane?
My code
import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; import javax.swing.plaf.basic.BasicTabbedPaneUI; public class HAAMS { //My Custom class for jTabbedPane public static class CustomMainMenuTabs extends BasicTabbedPaneUI { protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { Graphics2D g2 = (Graphics2D) g; Color color; if (isSelected) { color = new Color(74, 175, 211); } else if (getRolloverTab() == tabIndex) { color = new Color(45, 145, 180); } else {color = new Color(68, 67, 67);} g2.setPaint(color); g2.fill(new RoundRectangle2D.Double(x, y, w, h, 30, 30)); g2.fill(new Rectangle2D.Double(x + 100,y,w,h)); } } public static void main(String[] args) { JFrame MainScreen = new JFrame("Custom JTabbedPane"); MainScreen.setExtendedState(MainScreen.getExtendedState() | JFrame.MAXIMIZED_BOTH); //Setting UI for my jTabbedPane implementing my custom class CustomMainMenuTabs JTabbedPane jtpane = new JTabbedPane(2); jtpane.setUI(new CustomMainMenuTabs()); jtpane.add("1st Tabe", new JPanel()); jtpane.add("2nd Tabe", new JPanel()); jtpane.add("3rd Tabe", new JPanel()); MainScreen.getContentPane().add(jtpane); MainScreen.setVisible(true); } }
How to set the cursor to the HAND_CURSOR cursor when the mouse hovers over any tab, but not jpanel or any other component. It would be great if this were done without a mouse listener.