diff --git a/src/java.desktop/share/classes/javax/swing/JComponent.java b/src/java.desktop/share/classes/javax/swing/JComponent.java index 6351522ab49..87d6a41c2b0 100644 --- a/src/java.desktop/share/classes/javax/swing/JComponent.java +++ b/src/java.desktop/share/classes/javax/swing/JComponent.java @@ -31,6 +31,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.EventQueue; import java.awt.FocusTraversalPolicy; import java.awt.Font; import java.awt.FontMetrics; @@ -261,16 +262,6 @@ public abstract class JComponent extends Container implements Serializable, */ static boolean DEBUG_GRAPHICS_LOADED; - /** - * Key used to look up a value from the AppContext to determine the - * JComponent the InputVerifier is running for. That is, if - * AppContext.get(INPUT_VERIFIER_SOURCE_KEY) returns non-null, it - * indicates the EDT is calling into the InputVerifier from the - * returned component. - */ - private static final Object INPUT_VERIFIER_SOURCE_KEY = - new StringBuilder("InputVerifierSourceKey"); - /* The following fields support set methods for the corresponding * java.awt.Component properties. */ @@ -414,8 +405,7 @@ public abstract class JComponent extends Container implements Serializable, /** ActionMap. */ private ActionMap actionMap; - /** Key used to store the default locale in an AppContext **/ - private static final String defaultLocale = "JComponent.defaultLocale"; + private static volatile Locale defaultLocale; private static Component componentObtainingGraphicsFrom; private static Object componentObtainingGraphicsFromLock = new @@ -2841,12 +2831,12 @@ public abstract class JComponent extends Container implements Serializable, * @since 1.4 */ public static Locale getDefaultLocale() { - Locale l = (Locale) SwingUtilities.appContextGet(defaultLocale); - if( l == null ) { + Locale l = defaultLocale; + if (l == null) { //REMIND(bcb) choosing the default value is more complicated //than this. l = Locale.getDefault(); - JComponent.setDefaultLocale( l ); + JComponent.setDefaultLocale(l); } return l; } @@ -2865,8 +2855,8 @@ public abstract class JComponent extends Container implements Serializable, * @see #setLocale * @since 1.4 */ - public static void setDefaultLocale( Locale l ) { - SwingUtilities.appContextPut(defaultLocale, l); + public static void setDefaultLocale(Locale l) { + defaultLocale = l; } @@ -3507,7 +3497,7 @@ public abstract class JComponent extends Container implements Serializable, // This class is used by the KeyboardState class to provide a single - // instance that can be stored in the AppContext. + // instance. static final class IntVector { int[] array = null; int count = 0; @@ -3538,24 +3528,12 @@ public abstract class JComponent extends Container implements Serializable, } } + private static final IntVector intVector = new IntVector(); @SuppressWarnings("serial") static class KeyboardState implements Serializable { - private static final Object keyCodesKey = - JComponent.KeyboardState.class; - - // Get the array of key codes from the AppContext. - static IntVector getKeyCodeArray() { - IntVector iv = - (IntVector)SwingUtilities.appContextGet(keyCodesKey); - if (iv == null) { - iv = new IntVector(); - SwingUtilities.appContextPut(keyCodesKey, iv); - } - return iv; - } static void registerKeyPressed(int keyCode) { - IntVector kca = getKeyCodeArray(); + IntVector kca = intVector; int count = kca.size(); int i; for(i=0;i { - SunToolkit.createNewAppContext(); - SwingUtilities.invokeLater(() -> { - frame = new JFrame(); - component = new JLabel("Test Text"); - frame.add(component); - frame.setBounds(100, 100, 100, 100); - frame.setVisible(true); - startSwingLatch.countDown(); - }); - }).start(); - startSwingLatch.await(); - - AtomicReference caughtException = new AtomicReference<>(); - Thread checkThread = new Thread(getRootThreadGroup(), () -> { - try { - component.invalidate(); - component.revalidate(); - component.repaint(new Rectangle(0, 0, 0, 0)); - } catch (Exception e) { - caughtException.set(e); - } - }); - checkThread.start(); - checkThread.join(); - - if (caughtException.get() != null) { - throw new RuntimeException("Failed. Caught exception!", caughtException.get()); - } - } finally { - new Thread(swingTG, () -> SwingUtilities.invokeLater(() -> { - if (frame != null) { - frame.dispose(); - } - })).start(); - } - } - - private static ThreadGroup getRootThreadGroup() { - ThreadGroup currentTG = Thread.currentThread().getThreadGroup(); - ThreadGroup parentTG = currentTG.getParent(); - while (parentTG != null) { - currentTG = parentTG; - parentTG = currentTG.getParent(); - } - return currentTG; - } -}