Today while i was creating a JTabbedPane i noticed a weird (in my opinion) bug, which makes no sense...and since i am looking for this for more than 2 hours, can't find anything neither anything online.
Take a look at this:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.UnsupportedLookAndFeelException;
@SuppressWarnings("serial")
public class WhatTheHeck extends JPanel {
private final JTabbedPane pane = new JTabbedPane();
public WhatTheHeck() {
setLayout(new BorderLayout());
pane.addTab("1", new JTextField("first tf"));
pane.addTab("2", new JTextField("second tf"));
add(pane);
}
private void display() {
JFrame f = new JFrame("TabColors");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.setSize(new Dimension(300, 300));
// f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new WhatTheHeck().display();
}
});
}
}
I am editing the first one and change to 2nd tab. Everything ok.
HOWEVER!
If i edit the first textfield and while i am editing it i change my keyboard language (from english to greek or vice versa) with alt+shift...(windows 7) and change to the 2nd tab, i am getting the following stacktrace:
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location at java.awt.Component.getLocationOnScreen_NoTreeLock(Unknown Source) at java.awt.Component.getLocationOnScreen(Unknown Source) at javax.swing.text.JTextComponent$InputMethodRequestsHandler.getTextLocation(Unknown Source) at sun.awt.im.InputMethodContext.getTextLocation(Unknown Source) at sun.awt.windows.WInputMethod$1.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
I'm guessing something is up with alt shift that changes my keyboard language?
Is there a way to avoid getting this error?