javax.swing.text.JTextComponent类的使用及代码示例

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

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

JTextComponent介绍

暂无

代码示例

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

= new TableRowSorter<>(jTable.getModel());
private JTextField jtfFilter = new JTextField();
private JButton jbtFilter = new JButton("Filter");
  JPanel panel = new JPanel(new BorderLayout());
  panel.add(new JLabel("Specify a word to match:"),
      BorderLayout.WEST);
  panel.add(jtfFilter, BorderLayout.CENTER);
  setLayout(new BorderLayout());
  add(panel, BorderLayout.SOUTH);
  add(new JScrollPane(jTable), BorderLayout.CENTER);
  jtfFilter.getDocument().addDocumentListener(new DocumentListener(){
      String text = jtfFilter.getText();
      String text = jtfFilter.getText();
  SwingUtilities.invokeLater(new Runnable(){
    public void run() {
      JFrame frame = new JFrame("Row Filter");
      frame.add(new TestTableSortFilter());
      frame.pack();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);

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

private JTextField m_userInputTf = new JTextField(5);
private JTextField m_totalTf     = new JTextField(20);
private JButton    m_multiplyBtn = new JButton("Multiply");
private JButton    m_clearBtn    = new JButton("Clear");
  m_totalTf.setText(m_model.getValue());
  m_totalTf.setEditable(false);
  JPanel content = new JPanel();
  content.setLayout(new FlowLayout());
  content.add(new JLabel("Input"));
  content.add(m_userInputTf);
  content.add(m_multiplyBtn);
  content.add(new JLabel("Total"));
  this.setContentPane(content);
  this.pack();
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  m_totalTf.setText(INITIAL_VALUE);
  return m_userInputTf.getText();
  m_totalTf.setText(newTotal);

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

final JFrame frame = new JFrame("Text HIGHLIGHT");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel contentPane = new JPanel();
contentPane.setBorder(BorderFactory.createTitledBorder(
    BorderFactory.createEmptyBorder(5, 5, 5, 5), "Highlighter JTextArea"));
contentPane.add(scrollPane);
JButton remHighButton = new JButton("REMOVE HIGHLIGHT");
remHighButton.addActionListener(new ActionListener()
      Highlighter highlighter = tarea.getHighlighter();
      highlighter.removeHighlight(highlights.get(startIndex));
      tarea.setCaretPosition(startIndex);
      tarea.requestFocusInWindow();
      highlights.remove(startIndex);
JButton button = new JButton("HIGHLIGHT TEXT");
button.addActionListener(new ActionListener()
    text = tarea.getSelectedText();
    if (text != null && text.length() > 0)
      int startIndex = tarea.getText().indexOf(text);
      int endIndex = startIndex + text.length();
      Highlighter highlighter = tarea.getHighlighter();

代码示例来源:origin: RipMeApp/ripme

@Override
  public void actionPerformed(ActionEvent ae) {
    lastActionSelected = Actions.CUT;
    savedString = textComponent.getText();
    textComponent.cut();
  }
};

代码示例来源:origin: RipMeApp/ripme

@Override
  public void actionPerformed(ActionEvent ae) {
    textComponent.setText("");
    textComponent.replaceSelection(savedString);
    lastActionSelected = Actions.UNDO;
  }
};

代码示例来源:origin: RipMeApp/ripme

@Override
  public void actionPerformed(ActionEvent ae) {
    lastActionSelected = Actions.PASTE;
    savedString = textComponent.getText();
    textComponent.paste();
  }
};

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

private JTextField textField = new JTextField(10);
private JButton showDialogBtn = new JButton("Show Dialog");
private MyDialog myDialog = new MyDialog(this, "My Dialog");
 textField.setEditable(false);
   public void actionPerformed(ActionEvent e) {
    String text = myDialog.getTextFieldText();
    textField.setText(text);
 JPanel panel = new JPanel();
 panel.add(textField);
 panel.add(showDialogBtn);
 add(panel);
private JTextField textfield = new JTextField(10);
private JButton confirmBtn = new JButton("Confirm");
 JPanel panel = new JPanel();
 panel.add(textfield);
 panel.add(confirmBtn);
 return textfield.getText();

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

private WebEngine engine;
private JFrame frame = new JFrame();
private JPanel panel = new JPanel(new BorderLayout());
private JLabel lblStatus = new JLabel();
private JButton btnGo = new JButton("Go");
private JTextField txtURL = new JTextField();
private JProgressBar progressBar = new JProgressBar();
      loadURL(txtURL.getText());
  txtURL.addActionListener(al);
  panel.add(statusBar, BorderLayout.SOUTH);
  frame.getContentPane().add(panel);
          SwingUtilities.invokeLater(new Runnable() {
            @Override public void run() {
              txtURL.setText(newValue);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();
  frame.setVisible(true);

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

topPanel.removeAll();
mainPanel.removeAll();
topPanelBackButton.addActionListener(e -> openConfigList());
topPanelBackButton.setToolTipText("Back");
topPanel.add(topPanelBackButton, BorderLayout.WEST);
topPanel.add(listItem.createToggleButton(), BorderLayout.EAST);
    textField.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    textField.setText(configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
    textField.addFocusListener(new FocusAdapter()
      colorPickerBtn = new JButton("Pick a color");
      colorPickerBtn = new JButton(ColorUtil.toHexColor(existingColor).toUpperCase());
    colorPickerBtn.setFocusable(false);
    colorPickerBtn.setBackground(existingColor);
    colorPickerBtn.addMouseListener(new MouseAdapter()

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

addButton = new JButton("Add Comp");
  addButton.addActionListener(new ActionListener() {
  JPanel panel = new JPanel(new GridBagLayout());
  panel.add(addButton);
  return panel;
private JComboBox typeCombo = new JComboBox(new Object[]{"height", "length", "volume"});
private JComboBox relationCombo = new JComboBox(new Object[]{"above", "below", "between"});
private JTextField lowerField = new JTextField();
private JLabel labelAnd = new JLabel(" and ");
private JTextField upperField = new JTextField();
private JButton removeButton = new JButton("remove");
  typeCombo.setSelectedIndex(Comp.type);
  relationCombo.setSelectedIndex(Comp.relation);
  lowerField.setText(Comp.lower);
  upperField.setText(Comp.upper);
  enableUpper(Comp.relation == 2);
  return new Comp(typeCombo.getSelectedIndex(), relationCombo.getSelectedIndex(), lowerField.getText(), upperField.getText());

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

textfield.getDocument().addDocumentListener(this);
textfield.addPropertyChangeListener("foreground", this);
textfield.getDocument().removeDocumentListener(this);
textfield.removePropertyChangeListener("foreground", this);
isEmpty = textfield.getText().length() == 0;
foregroundColor = textfield.getForeground();
  unregisterListeners();
  try {
    textfield.setText("");
    textfield.setForeground(foregroundColor);
  } finally {
  unregisterListeners();
  try {
    textfield.setText(ghostText);
    textfield.setForeground(ghostColor);
  } finally {

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

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField f = new JTextField(10);
JPanel p = new JPanel();
p.add(f);
frame.add(p);
this.container = mainWindow;
this.suggestionFocusedColor = suggestionFocusedColor;
this.textField.getDocument().addDocumentListener(documentListener);
autoSuggestionPopUpWindow.setOpacity(opacity);
String text = textField.getText();
String wordBeingTyped = "";
if (text.contains(" ")) {
String text = textField.getText();
String typedWord = autoSuggestor.getCurrentlyTypedWord();
String t = text.substring(0, text.lastIndexOf(typedWord));
String tmp = t + text.substring(text.lastIndexOf(typedWord)).replace(typedWord, suggestedWord);
textField.setText(tmp + " ");

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

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter()
progressCurrent.setStringPainted(true);
txtDetails = new JTextArea(5, 50);
txtDetails.setEditable(false);
DefaultCaret caret = (DefaultCaret) txtDetails.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
JScrollPane scrollPane = new JScrollPane(txtDetails, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
btnCopy = new JButton("Copy");
btnCopy.setFocusPainted(false);
btnCopy.setEnabled(false);
  public void removeUpdate(DocumentEvent e)
    boolean bEnabled = txtSource.getText().length() > 0 && txtTarget.getText().length() > 0;
    btnCopy.setEnabled(bEnabled);
    boolean bEnabled = txtSource.getText().length() > 0 && txtTarget.getText().length() > 0;
    btnCopy.setEnabled(bEnabled);
txtSource.getDocument().addDocumentListener(listener);
txtTarget.getDocument().addDocumentListener(listener);
  File source = new File(txtSource.getText());
  File target = new File(txtTarget.getText());

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

JFrame frame = new JFrame("WindowCommunication");
 frame.getContentPane().add(new MyFramePanel());
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.pack();
 frame.setLocationRelativeTo(null);
 frame.setVisible(true);
private JTextField field = new JTextField(10);
private JButton openDialogeBtn = new JButton("Open Dialog");
 field.setEditable(false);
 field.setFocusable(false);
 add(field);
 add(openDialogeBtn);
 field.setText(dialogPanel.getFieldText());
private JTextField field = new JTextField(10);
private JButton okButton = new JButton("OK");
 return field.getText();

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

private static final String[] TEXTS = {"One", "Two", "Three", "Four", "Five"};
private ButtonGroup btnGroup = new ButtonGroup();
private JTextField textField = new JTextField(20);
 JPanel btnPanel = new JPanel(new GridLayout(1, 0, 5, 0));
 BtnListener btnListener = new BtnListener();
 for (String text : TEXTS) {
   toggleBtn.addActionListener(btnListener);
   toggleBtn.setActionCommand(text);
   btnPanel.add(toggleBtn);
   btnGroup.add(toggleBtn);
 JPanel otherPanel = new JPanel();
 otherPanel.add(textField ); // just to take focus elsewhere
 setLayout(new GridLayout(0, 1, 0, 15));
 add(btnPanel);
 add(otherPanel);
   textField.setText(aEvt.getActionCommand());
 BunchOfButtons mainPanel = new BunchOfButtons();

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

jTextField1 = new javax.swing.JTextField();
  jLabel2 = new javax.swing.JLabel();
  jButton1 = new javax.swing.JButton();
  gridBagConstraints.gridy = 0;
  gridBagConstraints.gridwidth = 3;
  getContentPane().add(jLabel1, gridBagConstraints);
  getContentPane().add(jButton1, gridBagConstraints);
  pack();
  getPresenter().getModel().setUser(jTextField1.getText());
  jTextField1.setText(getPresenter().getModel().getUser());
  setVisible(true);
  jTextField1.selectAll();
  jTextField1.requestFocus();
public void userRejected() {
  jLabel1.setText("Try again!");
  jTextField1.selectAll();
  jTextField1.requestFocus();

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

JFrame frame = new JFrame("Input Integer Example");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel contentPane = new JPanel();
contentPane.setBorder(
  BorderFactory.createEmptyBorder(5, 5, 5, 5));
tField = new JTextField(10);
((AbstractDocument)tField.getDocument()).setDocumentFilter(
    new MyDocumentFilter());        
contentPane.add(tField); 
frame.setContentPane(contentPane);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);

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

this.kind = kind;
f.setTitle("Echo " + kind);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getRootPane().setDefaultButton(send);
f.add(tf, BorderLayout.NORTH);
f.add(new JScrollPane(ta), BorderLayout.CENTER);
f.add(send, BorderLayout.SOUTH);
f.setLocation(kind.offset, 300);
f.pack();
send.addActionListener(this);
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
DefaultCaret caret = (DefaultCaret) ta.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
display(kind.activity + HOST + " on port " + PORT);
f.setVisible(true);
thread.start();
String s = tf.getText();
if (out != null) {
  out.println(s);
tf.setText("");

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

content.setMargin(new Insets(5, 5, 5, 5));
content.getDocument().addDocumentListener(new DocumentListener()
jfc.addPropertyChangeListener(new PropertyChangeListener() {
saveButton = new JButton("Save a File...");
saveButton.addActionListener(this);
JPanel buttonPanel = new JPanel(); 
buttonPanel.add(saveButton);
add(buttonPanel, BorderLayout.PAGE_START);
add(logScrollPane, BorderLayout.CENTER);        
  try {
    bw = new BufferedWriter(new FileWriter(file));
    bw.write(content.getText());
    bw.flush();
content.setCaretPosition(content.getDocument().getLength());
JFrame frame = new JFrame("FileChooserDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new MyFileChooser());
frame.pack();
frame.setVisible(true);

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

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
final JTextField textField = new JTextField("Enter text here...");
textField.addMouseListener(new MouseAdapter(){
  @Override
  public void mouseClicked(MouseEvent e){
    textField.setText("");
frame.add(textField);
frame.pack();
frame.setVisible(true);

相关文章

JTextComponent类方法