Search in sources :

Example 1 with DefaultCaret

use of javax.swing.text.DefaultCaret in project jdk8u_jdk by JetBrains.

the class bug7049024 method main.

public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame = new JFrame("Test");
            textField = new JTextField("test selection for textfield");
            button = new JButton("To compete the focus");
            frame.setLayout(new FlowLayout());
            frame.getContentPane().add(textField);
            frame.getContentPane().add(button);
            frame.pack();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
    });
    toolkit.realSync();
    clipboard = textField.getToolkit().getSystemSelection();
    if (null == clipboard) {
        return;
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            textField.requestFocusInWindow();
        }
    });
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            caret = (DefaultCaret) textField.getCaret();
            caret.setDot(2);
            caret.moveDot(4);
        }
    });
    toolkit.realSync();
    String oldSelection = (String) clipboard.getData(DataFlavor.stringFlavor);
    System.out.println("oldSelection is " + oldSelection);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            button.requestFocusInWindow();
        }
    });
    // So JTextField loses the focus.
    toolkit.realSync();
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            caret.setDot(4);
            caret.moveDot(6);
        }
    });
    toolkit.realSync();
    String newSelection = (String) clipboard.getData(DataFlavor.stringFlavor);
    System.out.println("newSelection is " + newSelection);
    boolean passed = newSelection.equals(oldSelection);
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            frame.dispose();
        }
    });
    if (!passed) {
        throw new RuntimeException("The test for bug 7049024 failed");
    }
}
Also used : DefaultCaret(javax.swing.text.DefaultCaret) SunToolkit(sun.awt.SunToolkit)

Example 2 with DefaultCaret

use of javax.swing.text.DefaultCaret in project jdk8u_jdk by JetBrains.

the class bug7083457 method main.

public static void main(String[] args) {
    DefaultCaret caret = new DefaultCaret();
    for (int i = 0; i < 10; i++) {
        boolean active = (i % 2 == 0);
        caret.setVisible(active);
        if (caret.isActive() != active) {
            throw new RuntimeException("caret.isActive() does not equal: " + active);
        }
    }
}
Also used : DefaultCaret(javax.swing.text.DefaultCaret)

Example 3 with DefaultCaret

use of javax.swing.text.DefaultCaret in project intellij-community by JetBrains.

the class FocusDebugger method init.

private JComponent init() {
    final JPanel result = new JPanel(new BorderLayout());
    myLogModel = new DefaultListModel();
    myLog = new JBList(myLogModel);
    myLog.setCellRenderer(new FocusElementRenderer());
    myAllocation = new JEditorPane();
    final DefaultCaret caret = new DefaultCaret();
    myAllocation.setCaret(caret);
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    myAllocation.setEditable(false);
    final Splitter splitter = new Splitter(true);
    splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myLog));
    splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(myAllocation));
    myLog.addListSelectionListener(this);
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this);
    result.add(splitter, BorderLayout.CENTER);
    final DefaultActionGroup group = new DefaultActionGroup();
    group.add(new ClearAction());
    result.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true).getComponent(), BorderLayout.NORTH);
    return result;
}
Also used : Splitter(com.intellij.openapi.ui.Splitter) DefaultCaret(javax.swing.text.DefaultCaret) JBList(com.intellij.ui.components.JBList)

Example 4 with DefaultCaret

use of javax.swing.text.DefaultCaret in project megameklab by MegaMek.

the class UnitUtil method showUnitCostBreakDown.

public static void showUnitCostBreakDown(Entity unit, JFrame frame) {
    HTMLEditorKit kit = new HTMLEditorKit();
    unit.calculateBattleValue(true, true);
    unit.getCost(true);
    JEditorPane textPane = new JEditorPane("text/html", "");
    JScrollPane scroll = new JScrollPane();
    textPane.setEditable(false);
    textPane.setCaret(new DefaultCaret());
    textPane.setEditorKit(kit);
    scroll.setViewportView(textPane);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    textPane.setText(unit.getBVText());
    scroll.setVisible(true);
    JDialog jdialog = new JDialog();
    jdialog.add(scroll);
    Dimension size = new Dimension(CConfig.getIntParam("WINDOWWIDTH") / 2, CConfig.getIntParam("WINDOWHEIGHT"));
    jdialog.setPreferredSize(size);
    jdialog.setMinimumSize(size);
    scroll.setPreferredSize(size);
    scroll.setMinimumSize(size);
    jdialog.setLocationRelativeTo(frame);
    jdialog.setVisible(true);
    try {
        textPane.setSelectionStart(0);
        textPane.setSelectionEnd(0);
    } catch (Exception ex) {
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultCaret(javax.swing.text.DefaultCaret) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Dimension(java.awt.Dimension) JDialog(javax.swing.JDialog) LocationFullException(megamek.common.LocationFullException)

Example 5 with DefaultCaret

use of javax.swing.text.DefaultCaret in project megameklab by MegaMek.

the class UnitUtil method showUnitWeightBreakDown.

public static void showUnitWeightBreakDown(Entity unit, JFrame frame) {
    TestEntity testEntity = getEntityVerifier(unit);
    JTextPane textPane = new JTextPane();
    JScrollPane scroll = new JScrollPane();
    textPane.setText(testEntity.printEntity().toString());
    textPane.setEditable(false);
    textPane.setCaret(new DefaultCaret());
    scroll.setViewportView(textPane);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    scroll.setVisible(true);
    JDialog jdialog = new JDialog();
    jdialog.add(scroll);
    Dimension size = new Dimension(CConfig.getIntParam("WINDOWWIDTH") / 2, CConfig.getIntParam("WINDOWHEIGHT"));
    jdialog.setPreferredSize(size);
    jdialog.setMinimumSize(size);
    scroll.setPreferredSize(size);
    scroll.setMinimumSize(size);
    jdialog.setLocationRelativeTo(frame);
    jdialog.setVisible(true);
    try {
        textPane.setSelectionStart(0);
        textPane.setSelectionEnd(0);
    } catch (Exception ex) {
    }
}
Also used : TestEntity(megamek.common.verifier.TestEntity) JScrollPane(javax.swing.JScrollPane) JTextPane(javax.swing.JTextPane) DefaultCaret(javax.swing.text.DefaultCaret) Dimension(java.awt.Dimension) JDialog(javax.swing.JDialog) LocationFullException(megamek.common.LocationFullException)

Aggregations

DefaultCaret (javax.swing.text.DefaultCaret)26 JScrollPane (javax.swing.JScrollPane)10 JTextArea (javax.swing.JTextArea)8 Dimension (java.awt.Dimension)5 JDialog (javax.swing.JDialog)4 Caret (javax.swing.text.Caret)4 LocationFullException (megamek.common.LocationFullException)4 BorderLayout (java.awt.BorderLayout)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JButton (javax.swing.JButton)3 JEditorPane (javax.swing.JEditorPane)3 JFrame (javax.swing.JFrame)3 JLabel (javax.swing.JLabel)3 Color (java.awt.Color)2 Point (java.awt.Point)2 FocusEvent (java.awt.event.FocusEvent)2 FocusListener (java.awt.event.FocusListener)2 JPanel (javax.swing.JPanel)2 JTextComponent (javax.swing.text.JTextComponent)2