javax.swing.text.JTextComponent.getDocument()方法的使用及代码示例

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

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

JTextComponent.getDocument介绍

暂无

代码示例

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

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

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

panel.add(textField);
PlainDocument doc = (PlainDocument) textField.getDocument();
doc.setDocumentFilter(new MyIntFilter());

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

panel.add(new JLabel("Specify a word to match:"),
    BorderLayout.WEST);
panel.add(jtfFilter, BorderLayout.CENTER);
add(panel, BorderLayout.SOUTH);
add(new JScrollPane(jTable), BorderLayout.CENTER);
jtfFilter.getDocument().addDocumentListener(new DocumentListener(){
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: camunda/camunda-bpm-platform

JLabel label = new JLabel("Filter Level:");
gridbag.setConstraints(label, c);
add(label);
add(label);
add(label);
c.gridy++;
final JTextField threadField = new JTextField("");
threadField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {
      aModel.setThreadFilter(threadField.getText());
catField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {
      aModel.setCategoryFilter(catField.getText());
ndcField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {
      aModel.setNDCFilter(ndcField.getText());
msgField.getDocument().addDocumentListener(new DocumentListener () {
    public void insertUpdate(DocumentEvent aEvent) {
      aModel.setMessageFilter(msgField.getText());

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

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);            
topPanel.add(tPane);
appendToPane(tPane, "flow", Color.ORANGE);
getContentPane().add(topPanel);
pack();
setVisible(true);   
aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
int len = tp.getDocument().getLength();
tp.setCaretPosition(len);
tp.setCharacterAttributes(aset, false);

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

textfield.getDocument().addDocumentListener(this);
  textfield.addPropertyChangeListener("foreground", this);
  textfield.getDocument().removeDocumentListener(this);
  textfield.removePropertyChangeListener("foreground", this);
JFrame frame = new JFrame("Test ghost text");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JTextField textField = new JTextField();
GhostText ghostText = new GhostText(textField, "Please enter some text here...");
textField.setPreferredSize(new Dimension(300, 24));
panel.add(textField);
panel.add(button);
frame.add(panel);
frame.pack();
frame.setVisible(true);
button.grabFocus();

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

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p.add(f);
frame.add(p);
frame.pack();
frame.setVisible(true);
this.container = mainWindow;
this.suggestionFocusedColor = suggestionFocusedColor;
this.textField.getDocument().addDocumentListener(documentListener);
            lastFocusableIndex = 0;
            sl.setFocused(false);
            autoSuggestionPopUpWindow.setVisible(false);
            setFocusToTextField();
      autoSuggestionPopUpWindow.setVisible(false);
      setFocusToTextField();
suggestionsPanel.add(suggestionLabel);

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

((AbstractDocument)pfPassword.getDocument()).setDocumentFilter(new LimitDocumentFilter(15));
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridBagLayout());
frame.add(pfPassword);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

content.getDocument().addDocumentListener(new DocumentListener()
buttonPanel.add(saveButton);
add(buttonPanel, BorderLayout.PAGE_START);
add(logScrollPane, BorderLayout.CENTER);        
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

field.getDocument().addDocumentListener(new DocumentListener() {
mainPanel.add(field);
mainPanel.add(field1);
JFrame frame = new JFrame("TextLabelMirror");
frame.getContentPane().add(new TextLabelMirror().getComponent());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

PlainDocument doc = (PlainDocument) textfield.getDocument();
doc.setDocumentFilter(new TextLengthDocFilter(3));
add(textfield);
JFrame frame = new JFrame("JTextFieldLimit2");
frame.getContentPane().add(new JTextFieldLimit2());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

JFrame frame = new JFrame(TestDifferentStyles.class.getSimpleName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
for (int i = 0; i < textPane.getDocument().getLength(); i++) {
  SimpleAttributeSet set = new SimpleAttributeSet();
frame.add(new JScrollPane(textPane));
frame.setSize(500, 400);
frame.setVisible(true);

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

JFrame frame = new JFrame("enter digit");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JSpinner jspinner = makeDigitsOnlySpinnerUsingDocumentFilter();
frame.getContentPane().add(jspinner, BorderLayout.CENTER);
frame.getContentPane().add(new JButton("just another widget"), BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
JSpinner spinner = new JSpinner(new SpinnerNumberModel(0, 0, 20, 1));
JSpinner.NumberEditor jsEditor = (JSpinner.NumberEditor) spinner.getEditor();
final Document jsDoc = jsEditor.getTextField().getDocument();
if (jsDoc instanceof PlainDocument) {
  AbstractDocument doc = new PlainDocument() {

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

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
};
txtSource.getDocument().addDocumentListener(listener);
txtTarget.getDocument().addDocumentListener(listener);
JPanel panProgressBars = new JPanel(new BorderLayout(0, 5));
panInputLabels.add(lblSource, BorderLayout.NORTH);
panInputLabels.add(lblTarget, BorderLayout.CENTER);
panInputFields.add(txtSource, BorderLayout.NORTH);
panInputFields.add(txtTarget, BorderLayout.CENTER);
panProgressLabels.add(lblProgressAll, BorderLayout.NORTH);
contentPane.add(panControls, BorderLayout.SOUTH);
pack();
setLocationRelativeTo(null);
  public void run()
    new FileCopierUtility().setVisible(true);

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

frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ta = new JTextArea();
DefaultCaret caret = (DefaultCaret) ta.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
frame.add(new JScrollPane(ta));
frame.setSize(400, 200);
frame.setVisible(true);
new UpdateText().execute();
public void process(List<String> chunks) {
  for (String s : chunks) {
    if (ta.getDocument().getLength() > 0) {
      ta.append("\n");

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

Document document = jTextArea.getDocument();
document.addDocumentListener(new ScrollingDocumentListener());
jScrollPane = new javax.swing.JScrollPane();
jTextArea = new javax.swing.JTextArea();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jScrollPane.setViewportView(jTextArea);
getContentPane().add(jScrollPane, java.awt.BorderLayout.CENTER);
setSize(320, 240);
setLocationRelativeTo(null);
java.awt.EventQueue.invokeLater(new Runnable() {
  public void run() {
    new ScrollingJTextAreaExample().setVisible(true);

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

import javax.swing.*;
import javax.swing.text.PlainDocument;

@SuppressWarnings("serial")
public class DocFilterExample extends JPanel {
  private static final int ROWS = 30;
  private static final int COLS = 40;

  private JTextArea textArea = new JTextArea(ROWS, COLS);

  public DocFilterExample() {
    ((PlainDocument) textArea.getDocument()).setDocumentFilter(new XcharFilter());

    add(new JScrollPane(textArea));
  }

  private static void createAndShowGui() {
    JFrame frame = new JFrame("DocFilterExample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new DocFilterExample());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }

  public static void main(String[] args) {
    SwingUtilities.invokeLater(() -> createAndShowGui());
  }
}

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

mirroredEditor.setDocument(editor.getDocument());
final JFrame frame = new JFrame("mirrored label");
final JPanel mirrorPanel = new JPanel(new GridLayout(1, 2));
mirrorPanel.add(new JScrollPane(editor));
mirrorPanel.add(new JScrollPane(mirroredEditor));
frame.add(mirrorPanel);
frame.pack();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setVisible(true);

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

import javax.swing.*;
import javax.swing.text.PlainDocument;

public class LimitLinesDocumentFilterTest {
  private static void createAndShowUI() {
   int rows = 10;
   int cols = 30;
   JTextArea textarea = new JTextArea(rows , cols );
   PlainDocument doc = (PlainDocument)textarea.getDocument();
   int maxLineCount = 9;
   doc.setDocumentFilter(new LimitLinesDocumentFilter(maxLineCount ));

   JFrame frame = new JFrame("Limit Lines Document Filter Test");
   frame.getContentPane().add(new JScrollPane(textarea));
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.pack();
   frame.setLocationRelativeTo(null);
   frame.setVisible(true);
  }

  public static void main(String[] args) {
   java.awt.EventQueue.invokeLater(new Runnable() {
     public void run() {
      createAndShowUI();
     }
   });
  }
}

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

import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.FlowLayout;
public class MainClass extends JFrame {
private JPanel contentPane;
private JFormattedTextField MyTextField;
public static void main(String[] args) {
  new MainClass();
}
public MainClass() {
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setBounds(100, 100, 450, 300);
  contentPane = new JPanel();
  contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  setContentPane(contentPane);
  contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
  MyTextField=new JFormattedTextField();
  MyTextField.setColumns(20);
  MyTextField.getDocument().addDocumentListener(new MyDocumentListener());
  contentPane.add(MyTextField);
  this.setVisible(true);
 }
 }

相关文章

JTextComponent类方法