Java Code Examples for java.awt.font.TextHitInfo#trailing()

The following examples show how to use java.awt.font.TextHitInfo#trailing() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextMeasureTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 2
Source File: TextMeasureTests.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 3
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 4
Source File: TextMeasureTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 5
Source File: TextMeasureTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 6
Source File: TextMeasureTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 7
Source File: TextMeasureTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 8
Source File: TextMeasureTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 9
Source File: TextMeasureTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 10
Source File: TextMeasureTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(TestEnvironment env, Result results) {
    super.init(env, results);

    ArrayList list = new ArrayList(text.length() * 2 + 2);
    TextHitInfo hit = TextHitInfo.trailing(-1);
    do {
        list.add(hit);
        hit = tl.getNextRightHit(hit);
    } while (hit != null);
    hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);

    lb = tl.getBounds();
    lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
 
Example 11
Source File: bug8041990.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 12
Source File: bug8041990.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 13
Source File: bug8041990.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 14
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Draws the string at the specified location underlining the specified
 * character.
 *
 * @param c JComponent that will display the string, may be null
 * @param g Graphics to draw the text to
 * @param text String to display
 * @param underlinedIndex Index of a character in the string to underline
 * @param x X coordinate to draw the text at
 * @param y Y coordinate to draw the text at
 * @param useFPAPI use floating point API
 */
public static void drawStringUnderlineCharAt(JComponent c, Graphics g,
                                             String text, int underlinedIndex,
                                             float x, float y,
                                             boolean useFPAPI) {
    if (text == null || text.length() <= 0) {
        return;
    }
    SwingUtilities2.drawString(c, g, text, x, y, useFPAPI);
    int textLength = text.length();
    if (underlinedIndex >= 0 && underlinedIndex < textLength ) {
        float underlineRectY = y;
        int underlineRectHeight = 1;
        float underlineRectX = 0;
        int underlineRectWidth = 0;
        boolean isPrinting = isPrinting(g);
        boolean needsTextLayout = isPrinting;
        if (!needsTextLayout) {
            synchronized (charsBufferLock) {
                syncCharsBuffer(text);
                needsTextLayout =
                    isComplexLayout(charsBuffer, 0, textLength);
            }
        }
        if (!needsTextLayout) {
            FontMetrics fm = g.getFontMetrics();
            underlineRectX = x +
                SwingUtilities2.stringWidth(c,fm,
                                    text.substring(0,underlinedIndex));
            underlineRectWidth = fm.charWidth(text.
                                              charAt(underlinedIndex));
        } else {
            Graphics2D g2d = getGraphics2D(g);
            if (g2d != null) {
                TextLayout layout =
                    createTextLayout(c, text, g2d.getFont(),
                                   g2d.getFontRenderContext());
                if (isPrinting) {
                    float screenWidth = (float)g2d.getFont().
                        getStringBounds(text, getFontRenderContext(c)).getWidth();
                    // If text fits the screenWidth, then do not need to justify
                    if (SwingUtilities2.stringWidth(c, g2d.getFontMetrics(),
                                                    text) > screenWidth) {
                        layout = layout.getJustifiedLayout(screenWidth);
                    }
                }
                TextHitInfo leading =
                    TextHitInfo.leading(underlinedIndex);
                TextHitInfo trailing =
                    TextHitInfo.trailing(underlinedIndex);
                Shape shape =
                    layout.getVisualHighlightShape(leading, trailing);
                Rectangle rect = shape.getBounds();
                underlineRectX = x + rect.x;
                underlineRectWidth = rect.width;
            }
        }
        g.fillRect((int) underlineRectX, (int) underlineRectY + 1,
                   underlineRectWidth, underlineRectHeight);
    }
}
 
Example 15
Source File: bug8041990.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 16
Source File: bug8041990.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 17
Source File: bug8041990.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 18
Source File: bug8041990.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 19
Source File: bug8041990.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}
 
Example 20
Source File: bug8041990.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    ThreadGroup stubTG = new ThreadGroup(getRootThreadGroup(), "Stub Thread Group");
    ThreadGroup swingTG = new ThreadGroup(getRootThreadGroup(), "SwingTG");
    try {
        Thread stubThread = new Thread(stubTG, SunToolkit::createNewAppContext);
        stubThread.start();
        stubThread.join();

        CountDownLatch startSwingLatch = new CountDownLatch(1);
        new Thread(swingTG, () -> {
            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<Exception> caughtException = new AtomicReference<>();
        Thread checkThread = new Thread(getRootThreadGroup(), () -> {
            try {
                // If the bug is present this will throw exception
                new InputMethodEvent(component,
                        InputMethodEvent.CARET_POSITION_CHANGED,
                        TextHitInfo.leading(0),
                        TextHitInfo.trailing(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();
    }
}