-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
1.4.0, 5.0
-
Fix Understood
-
generic
-
generic
On changing LookAndFeel of JTabbedPane, it resets the focus of the child tabs to
starting child tab.
To reproduce :
1. Compile and execute the attached code.
2. Scroll the tabs till the end, i.e., Testing Tab9.
3. Select that tab by clicking on the child tab containing 'Testing Tab9'.
4. You will see the main tab containing button labeled 'Test Button9'.
Click on it, which will change the lookandfeel.
You will see that the child tabs have been scrolled back to starting child tab,
i.e., 'Testing Tab0', where as the selected tab is still 'Testing Tab9'.
Adding the test case here (TabbedPaneBugWithLNF.java) at
the request of the jdk.dev.java.net community:
import javax.swing.*;
import javax.swing.plaf.basic.*;
import java.awt.*;
import java.awt.event.*;
import javasoft.sqerobot.*;
public class TabbedPaneBugWithLNF extends JFrame {
ProbeRobot probe;
String LNF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
JTabbedPane tabPane;
JButton testBtn;
String labelOfCurrentJBtn = null;
public TabbedPaneBugWithLNF() {
super("TabbedPaneBugWithLNF");
setSize(640,180);
try {
probe = new ProbeRobot( new Robot());
} catch (Exception e) {
e.printStackTrace();
}
tabPane = new JTabbedPane(JTabbedPane.BOTTOM,JTabbedPane.SCROLL_TAB_LAYOUT);
tabPane.addTab("Testing Tab0", testBtn = new JButton("Test Button0"));
tabPane.addTab("Testing Tab1", testBtn = new JButton("Test Button1"));
tabPane.addTab("Testing Tab2", testBtn = new JButton("Test Button2"));
tabPane.addTab("Testing Tab3", testBtn = new JButton("Test Button3"));
tabPane.addTab("Testing Tab4", testBtn = new JButton("Test Button4"));
tabPane.addTab("Testing Tab5", testBtn = new JButton("Test Button5"));
tabPane.addTab("Testing Tab6", testBtn = new JButton("Test Button6"));
tabPane.addTab("Testing Tab7", testBtn = new JButton("Test Button7"));
tabPane.addTab("Testing Tab8", testBtn = new JButton("Test Button8"));
JButton myBtn = null;
tabPane.addTab("Testing Tab9", myBtn = new JButton("Test Button9"));
myBtn.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
UIManager.setLookAndFeel(LNF);
SwingUtilities.updateComponentTreeUI(TabbedPaneBugWithLNF.this);
}
catch (Exception exc) {
System.out.println("Error changing L&F : " + LNF);
}
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(tabPane);
setVisible(true);
tabPane.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
System.out.println("Mouse x::> " + me.getX() + " Mouse y::> " + me.getY());
}
});
Point src = new Point(0,0);
Point scrollLeftBtnLoc = null;
Point scrollRightBtnLoc = null;
Point dest = null;
int noOfTabs = tabPane.getTabCount();
}
public Point getChildTabLocation(int index) {
Rectangle rect = tabPane.getBoundsAt(index);
Point tabP = tabPane.getLocationOnScreen();
Point p = rect.getLocation();
System.out.println("Tab counter >> " + index);
int width = (int)rect.getWidth() / 2;
int height = (int)rect.getHeight() / 2;
//System.out.println("Tab x : >> " + p.x + " y ::: " + p.y);
p.x = Math.abs(p.x);
p.y = Math.abs(p.y);
p.translate(width, height);
p.translate(tabP.x, tabP.y);
return p;
}
public static void main(String[] args) {
System.out.println("Hello World!");
new TabbedPaneBugWithLNF();
}
}
starting child tab.
To reproduce :
1. Compile and execute the attached code.
2. Scroll the tabs till the end, i.e., Testing Tab9.
3. Select that tab by clicking on the child tab containing 'Testing Tab9'.
4. You will see the main tab containing button labeled 'Test Button9'.
Click on it, which will change the lookandfeel.
You will see that the child tabs have been scrolled back to starting child tab,
i.e., 'Testing Tab0', where as the selected tab is still 'Testing Tab9'.
Adding the test case here (TabbedPaneBugWithLNF.java) at
the request of the jdk.dev.java.net community:
import javax.swing.*;
import javax.swing.plaf.basic.*;
import java.awt.*;
import java.awt.event.*;
import javasoft.sqerobot.*;
public class TabbedPaneBugWithLNF extends JFrame {
ProbeRobot probe;
String LNF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
JTabbedPane tabPane;
JButton testBtn;
String labelOfCurrentJBtn = null;
public TabbedPaneBugWithLNF() {
super("TabbedPaneBugWithLNF");
setSize(640,180);
try {
probe = new ProbeRobot( new Robot());
} catch (Exception e) {
e.printStackTrace();
}
tabPane = new JTabbedPane(JTabbedPane.BOTTOM,JTabbedPane.SCROLL_TAB_LAYOUT);
tabPane.addTab("Testing Tab0", testBtn = new JButton("Test Button0"));
tabPane.addTab("Testing Tab1", testBtn = new JButton("Test Button1"));
tabPane.addTab("Testing Tab2", testBtn = new JButton("Test Button2"));
tabPane.addTab("Testing Tab3", testBtn = new JButton("Test Button3"));
tabPane.addTab("Testing Tab4", testBtn = new JButton("Test Button4"));
tabPane.addTab("Testing Tab5", testBtn = new JButton("Test Button5"));
tabPane.addTab("Testing Tab6", testBtn = new JButton("Test Button6"));
tabPane.addTab("Testing Tab7", testBtn = new JButton("Test Button7"));
tabPane.addTab("Testing Tab8", testBtn = new JButton("Test Button8"));
JButton myBtn = null;
tabPane.addTab("Testing Tab9", myBtn = new JButton("Test Button9"));
myBtn.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
UIManager.setLookAndFeel(LNF);
SwingUtilities.updateComponentTreeUI(TabbedPaneBugWithLNF.this);
}
catch (Exception exc) {
System.out.println("Error changing L&F : " + LNF);
}
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(tabPane);
setVisible(true);
tabPane.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent me) {
System.out.println("Mouse x::> " + me.getX() + " Mouse y::> " + me.getY());
}
});
Point src = new Point(0,0);
Point scrollLeftBtnLoc = null;
Point scrollRightBtnLoc = null;
Point dest = null;
int noOfTabs = tabPane.getTabCount();
}
public Point getChildTabLocation(int index) {
Rectangle rect = tabPane.getBoundsAt(index);
Point tabP = tabPane.getLocationOnScreen();
Point p = rect.getLocation();
System.out.println("Tab counter >> " + index);
int width = (int)rect.getWidth() / 2;
int height = (int)rect.getHeight() / 2;
//System.out.println("Tab x : >> " + p.x + " y ::: " + p.y);
p.x = Math.abs(p.x);
p.y = Math.abs(p.y);
p.translate(width, height);
p.translate(tabP.x, tabP.y);
return p;
}
public static void main(String[] args) {
System.out.println("Hello World!");
new TabbedPaneBugWithLNF();
}
}
- duplicates
-
JDK-4974150 After changing the LAf tabPlacement of Tabs is not proper in scroll Layout Polic
-
- Closed
-