javax.swing.JTextArea.setCaretPosition()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(240)

本文整理了Java中javax.swing.JTextArea.setCaretPosition()方法的一些代码示例,展示了JTextArea.setCaretPosition()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextArea.setCaretPosition()方法的具体详情如下:
包路径:javax.swing.JTextArea
类名称:JTextArea
方法名:setCaretPosition

JTextArea.setCaretPosition介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

public void run () {
    ui.textArea.append("" + c);
    ui.textArea.setCaretPosition(ui.textArea.getDocument().getLength());
  }
});

代码示例来源:origin: libgdx/libgdx

public void run () {
    ui.textArea.append(text + "\n");
    ui.textArea.setCaretPosition(ui.textArea.getDocument().getLength());
  }
});

代码示例来源:origin: JetBrains/ideavim

public void setText(@NotNull String data) {
 if (data.length() > 0 && data.charAt(data.length() - 1) == '\n') {
  data = data.substring(0, data.length() - 1);
 }
 myText.setText(data);
 myText.setCaretPosition(0);
 if (data.length() > 0) {
  activate();
 }
}

代码示例来源:origin: igniterealtime/Smack

@Override
  public void valueChanged(ListSelectionEvent e) {
    if (table.getSelectedRow() == -1) {
      // Clear the messageTextArea since there is none packet selected
      messageTextArea.setText(null);
    }
    else {
      // Set the detail of the packet in the messageTextArea
      messageTextArea.setText(
          (String) table.getModel().getValueAt(table.getSelectedRow(), 0));
      // Scroll up to the top
      messageTextArea.setCaretPosition(0);
    }
  }
}

代码示例来源:origin: pmd/pmd

private void populateResultArea() {
  int[] selectionIndices = resultsTable.getSelectedRows();
  TableModel model = resultsTable.getModel();
  List<Match> selections = new ArrayList<>(selectionIndices.length);
  for (int i = 0; i < selectionIndices.length; i++) {
    selections.add((Match) model.getValueAt(selectionIndices[i], 99));
  }
  String report = new SimpleRenderer(trimLeadingWhitespace).render(selections.iterator());
  resultsTextArea.setText(report);
  resultsTextArea.setCaretPosition(0); // move to the top
}

代码示例来源:origin: wiztools/rest-client

@Override
public void setBody(byte[] body, ContentType type) {
  // Call the super method
  super.setBody(body, type);
  
  // Set the hex display value
  jta.setText(HexDump.getHexDataDumpAsString(body));
  jta.setCaretPosition(0);
}

代码示例来源:origin: 4thline/cling

@Override
  public void run() {
    errorWindow.getContentPane().removeAll();
    JTextArea textArea = new JTextArea();
    textArea.setEditable(false);
    StringBuilder text = new StringBuilder();
    text.append("An exceptional error occurred!\nYou can try to continue or exit the application.\n\n");
    text.append("Please tell us about this here:\nhttp://www.4thline.org/projects/mailinglists-cling.html\n\n");
    text.append("-------------------------------------------------------------------------------------------------------------\n\n");
    Writer stackTrace = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stackTrace));
    text.append(stackTrace.toString());
    textArea.setText(text.toString());
    JScrollPane pane = new JScrollPane(textArea);
    errorWindow.getContentPane().add(pane, BorderLayout.CENTER);
    JButton exitButton = new JButton("Exit Application");
    exitButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        System.exit(1);
      }
    });
    errorWindow.getContentPane().add(exitButton, BorderLayout.SOUTH);
    errorWindow.pack();
    Application.center(errorWindow);
    textArea.setCaretPosition(0);
    errorWindow.setVisible(true);
  }
});

代码示例来源:origin: kiegroup/optaplanner

ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
contentPanel.add(stackTraceScrollPane, BorderLayout.CENTER);
stackTraceTextArea.setCaretPosition(0); // Scroll to top
JPanel buttonPanel = new JPanel(new GridLayout(1, 0));
JButton closeButton = new JButton(new AbstractAction("Close") {

代码示例来源:origin: wiztools/rest-client

jta_trace.setCaretPosition(0);
jsp_jta_trace.setPreferredSize(d);

代码示例来源:origin: wiztools/rest-client

private void loadFromFile(File f) {
  if(f != null){
    try{
      String content = FileUtil.getContentAsString(f, Charsets.UTF_8);
      Dimension d = jsp_in.getPreferredSize();
      jta_in.setText(content);
      jta_in.setCaretPosition(0);
      jsp_in.setPreferredSize(d);
    }
    catch(IOException ex){
      ui.getView().showError(Util.getStackTrace(ex));
    }
  }
}

代码示例来源:origin: kiegroup/optaplanner

= constraintMatchTotalList.get(selectedRow);
detailTextArea.setText(buildConstraintMatchSetText(constraintMatchTotal));
detailTextArea.setCaretPosition(0);

代码示例来源:origin: wiztools/rest-client

void showMessage(final String title, final String message){
  messageDialog.setTitle(title);
  jta_error.setText(message);
  jta_error.setCaretPosition(0);
  messageDialog.setLocationRelativeTo(ui.getFrame());
  jb_ok.requestFocus();
  messageDialog.setVisible(true);
}

代码示例来源:origin: stackoverflow.com

textArea.setCaretPosition(pos + findLength);
textArea.moveCaretPosition(pos);

代码示例来源:origin: kiegroup/optaplanner

private CheckBoxTree createCheckBoxTree() {
  final CheckBoxTree resultCheckBoxTree = new CheckBoxTree(initBenchmarkHierarchy(true));
  resultCheckBoxTree.addTreeSelectionListener(e -> {
    TreePath treeSelectionPath = e.getNewLeadSelectionPath();
    if (treeSelectionPath != null) {
      DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treeSelectionPath.getLastPathComponent();
      MixedCheckBox checkBox = (MixedCheckBox) treeNode.getUserObject();
      detailTextArea.setText(checkBox.getDetail());
      detailTextArea.setCaretPosition(0);
      renameNodeButton.setEnabled(checkBox.getBenchmarkResult() instanceof PlannerBenchmarkResult
          || checkBox.getBenchmarkResult() instanceof SolverBenchmarkResult);
    }
  });
  resultCheckBoxTree.addMouseListener(new MouseAdapter() {
    @Override
    public void mousePressed(MouseEvent e) {
      // Enable button if checked singleBenchmarkResults exist
      generateReportButton.setEnabled(!resultCheckBoxTree.getSelectedSingleBenchmarkNodes().isEmpty());
    }
  });
  checkBoxTree = resultCheckBoxTree;
  return resultCheckBoxTree;
}

代码示例来源:origin: checkstyle/checkstyle

/**
 * Set selection.
 */
public void select() {
  pModel.findSelectionPositions();
  editor.setSelectedTextColor(Color.blue);
  editor.requestFocusInWindow();
  editor.setCaretPosition(pModel.getSelectionStart());
  editor.moveCaretPosition(pModel.getSelectionEnd());
}

代码示例来源:origin: wiztools/rest-client

body = data;
jta.setText(HexDump.getHexDataDumpAsString(data));
jta.setCaretPosition(0);

代码示例来源:origin: fossasia/neurolab-desktop

@Override
  public void write(int b) throws IOException {
    // redirects data to the text area
    textArea.append(String.valueOf((char)b));
    // scrolls the text area to the end of data
    textArea.setCaretPosition(textArea.getDocument().getLength());
  }
}

代码示例来源:origin: winder/Universal-G-Code-Sender

private void checkScrollWindow() {
  // Console output.
  DefaultCaret caret = (DefaultCaret)consoleTextArea.getCaret();
  if (scrollWindowCheckBox.isSelected()) {
   caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
   consoleTextArea.setCaretPosition(consoleTextArea.getDocument().getLength());
  } else {
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
  }
  
  // Command table.
  this.commandTable.setAutoWindowScroll(scrollWindowCheckBox.isSelected());
}

代码示例来源:origin: winder/Universal-G-Code-Sender

private void checkScrollWindow() {
  // Console output.
  DefaultCaret caret = (DefaultCaret)consoleTextArea.getCaret();
  if (scrollWindowMenuItem.isSelected()) {
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    consoleTextArea.setCaretPosition(consoleTextArea.getDocument().getLength());
  } else {
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
  }
}

代码示例来源:origin: magefree/mage

public void showDialog(String title, String message) {
  this.setTitle(title);
  this.lblMessage.setText(message);
  this.lblMessage.setCaretPosition(0);
  this.pack();
  this.revalidate();
  this.repaint();
  this.setModal(true);
  this.setVisible(true);
}

相关文章

JTextArea类方法