Java Code Examples for javax.swing.JTextArea.insert()

The following are Jave code examples for showing how to use insert() of the javax.swing.JTextArea class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OpenJSharp   File: LWTextAreaPeer.java   Source Code and License Vote up 6 votes
@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength()
                                 && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
 
Example 2
Project: jdk8u-jdk   File: LWTextAreaPeer.java   Source Code and License Vote up 6 votes
@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength()
                                 && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
 
Example 3
Project: openjdk-jdk10   File: LWTextAreaPeer.java   Source Code and License Vote up 6 votes
@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength()
                                 && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
 
Example 4
Project: freecol   File: EmigrationDialog.java   Source Code and License Vote up 5 votes
/**
 * The constructor to use.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param europe The {@code Europe} where we can find the
 *     units that are prepared to emigrate.
 * @param foy Is this emigration due to a fountain of youth?
 */
public EmigrationDialog(FreeColClient freeColClient, JFrame frame,
        Europe europe, boolean foy) {
    super(freeColClient, frame);

    final ImageLibrary lib = freeColClient.getGUI().getImageLibrary();
    final List<AbstractUnit> recruitables
        = new ArrayList<>(europe.getExpandedRecruitables(false));

    JTextArea header
        = Utility.localizedTextArea("emigrationDialog.chooseImmigrant");
    if (foy) {
        header.insert(Messages.message(LostCityRumour.RumourType.FOUNTAIN_OF_YOUTH.getDescriptionKey())
                      + "\n\n", 0);
    }

    MigPanel panel = new MigPanel(new MigLayout("wrap 1", "[fill]", ""));
    panel.add(header, "wrap 20");
    panel.setSize(panel.getPreferredSize());

    List<ChoiceItem<Integer>> c = choices();
    int i = Europe.MigrationType.getDefaultSlot();
    AbstractUnit a0 = recruitables.remove(0);
    c.add(new ChoiceItem<>(Messages.message(a0.getSingleLabel()), i++)
        .defaultOption()
        .setIcon(new ImageIcon(getSmallAbstractUnitImage(a0))));
    for (AbstractUnit au : recruitables) {
        c.add(new ChoiceItem<>(Messages.message(au.getSingleLabel()), i++)
            .setIcon(new ImageIcon(getSmallAbstractUnitImage(au))));
    }

    initializeChoiceDialog(frame, false, panel, null, null, c);
}
 
Example 5
Project: FreeCol   File: EmigrationDialog.java   Source Code and License Vote up 5 votes
/**
 * The constructor to use.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param frame The owner frame.
 * @param europe The {@code Europe} where we can find the
 *     units that are prepared to emigrate.
 * @param foy Is this emigration due to a fountain of youth?
 */
public EmigrationDialog(FreeColClient freeColClient, JFrame frame,
        Europe europe, boolean foy) {
    super(freeColClient, frame);

    final ImageLibrary lib = freeColClient.getGUI().getImageLibrary();
    final List<AbstractUnit> recruitables
        = new ArrayList<>(europe.getExpandedRecruitables(false));

    JTextArea header
        = Utility.localizedTextArea("emigrationDialog.chooseImmigrant");
    if (foy) {
        header.insert(Messages.message(LostCityRumour.RumourType.FOUNTAIN_OF_YOUTH.getDescriptionKey())
                      + "\n\n", 0);
    }

    MigPanel panel = new MigPanel(new MigLayout("wrap 1", "[fill]", ""));
    panel.add(header, "wrap 20");
    panel.setSize(panel.getPreferredSize());

    List<ChoiceItem<Integer>> c = choices();
    int i = Europe.MigrationType.getDefaultSlot();
    AbstractUnit a0 = recruitables.remove(0);
    c.add(new ChoiceItem<>(Messages.message(a0.getSingleLabel()), i++)
        .defaultOption()
        .setIcon(new ImageIcon(getSmallAbstractUnitImage(a0))));
    for (AbstractUnit au : recruitables) {
        c.add(new ChoiceItem<>(Messages.message(au.getSingleLabel()), i++)
            .setIcon(new ImageIcon(getSmallAbstractUnitImage(au))));
    }

    initializeChoiceDialog(frame, false, panel, null, null, c);
}