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");
}
}
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);
}
}
}
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;
}
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) {
}
}
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) {
}
}
Aggregations