Package javax.swing

Examples of javax.swing.JTextPane


*
* @param f report field
* @param str label text
*/
public SwingTextField(Field f, String str) {
    super(f, new JTextPane());
    JTextPane textPane = (JTextPane)getComponent();
    textPane.setText(str);
    textPane.setEditable(false);
    format();
}
View Full Code Here


/**
* Formats the label according to the field's formatting specifications.
*/
public void format() {
    JTextPane textPane = (JTextPane)getComponent();

    Format format = field.getFormat();
    Style style = StyleContext.getDefaultStyleContext()
  .getStyle(StyleContext.DEFAULT_STYLE);

    // Save selection and select all text
    int selStart = textPane.getSelectionStart();
    int selEnd = textPane.getSelectionEnd();
    textPane.selectAll();

    StyleConstants.setBold(style, format.isBold());
    StyleConstants.setItalic(style, format.isItalic());
    StyleConstants.setUnderline(style, format.isUnderline());
    StyleConstants.setFontSize(style, (int)format.getSize());
    StyleConstants.setFontFamily(style, format.getFontFamilyName());

    // Color is based on visibility flag of field
    StyleConstants.setForeground(style, getColor(format));

    // Align
    switch (format.getAlign()) {
    case Format.ALIGN_CENTER:
  StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER);
  break;
    case Format.ALIGN_RIGHT:
  StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT);
  break;
    default:
  StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT);
  break;
    }
    textPane.setParagraphAttributes(style, true);

    // Restore selection
    textPane.setCaretPosition(selStart);
    textPane.moveCaretPosition(selEnd);

    makeBorders();
}
View Full Code Here

    }

    if (!selected)
  select(true);

    JTextPane textPane = (JTextPane)getComponent();
    textPane.setEditable(true);
    textPane.getCaret().setVisible(true);
    textPane.requestFocus();
    origHeight = textPane.getBounds().height;

    sectionWidget.designer.setIgnoreKeys(true);

    textPane.removeMouseListener(this);
    textPane.removeMouseMotionListener(this);

    changingEditState = false;

    typingCommand = new TypingCommand(this, origHeight);
}
View Full Code Here

* method.
*
* @param e a mouse event
*/
protected void cursorForPosition(MouseEvent e) {
    JTextPane textPane = (JTextPane)getComponent();
    if (textPane.isEditable())
  textPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    else
  super.cursorForPosition(e);
}
View Full Code Here

*/
public void keyTyped(KeyEvent e) {
    char c = e.getKeyChar();
    int pos;
    java.awt.Rectangle bounds;
    JTextPane textPane = (JTextPane)getComponent();

    switch (c) {
    case KeyEvent.VK_ENTER:
  // We've just grown. Make sure we still fit.
  bounds = getComponent().getBounds();
  bounds.height += lineHeight;
  getComponent().setBounds(bounds);

  // Make sure we still fit in section
  sectionWidget.growToFit();
  break;
    case KeyEvent.VK_BACK_SPACE:
  try {
      pos = textPane.getCaretPosition();
      if (pos > 0 && textPane.getText(pos - 1, 1).equals("\n")) {
    bounds = textPane.getBounds();
    bounds.height -= lineHeight;
    textPane.setBounds(bounds);
      }
  }
  catch (BadLocationException ex) {}
  break;
    case KeyEvent.VK_DELETE:
  try {
      pos = textPane.getCaretPosition();
      if (pos < textPane.getText().length()
    && textPane.getText(pos, 1).equals("\n"))
      {
    bounds = textPane.getBounds();
    bounds.height -= lineHeight;
    textPane.setBounds(bounds);
      }
  }
  catch (BadLocationException ex2) {}
  break;
    }
View Full Code Here

/**
* Saves new text. The type has already been performed by the user.
*/
public void perform() {
    JTextPane textPane = (JTextPane)fw.getComponent();
    if (textPane.isEditable()) {
  // If we wait until later to grab the text, then we loose text with
  // newlines in it. I don't know why. Go figure. It may be the
  // updates caused by the bounds change that cause it; I don't know.
  newText = textPane.getText();

  textPane.setEditable(false);
  textPane.getCaret().setVisible(false);

  newBounds = new Rectangle(textPane.getBounds());
  if (newBounds.height != origHeight)
      fw.getField().getBounds().setBounds(newBounds);

  // Set text after settings bounds because setting the text triggers
  // an update which in turn re-sets the field's bounds, erasing any
  // changes we made in keyTyped().
  //
  // See also the note above: we must retrieve the text from the edit
  // widget before getting here.
  fw.getField().setValue(newText);

  fw.getSectionWidget().setIgnoreKeys(false);

  textPane.addMouseListener(fw);
  textPane.addMouseMotionListener(fw);
    }

    sectionResizeCommand.perform();
}
View Full Code Here

    textPaneInfo.addProperty("horizontalScrollBar", "bool", Boolean.FALSE);
  };

  public TextPane(Widget parent, String name) throws GUIException {
    super(parent, name);
    textPane = new JTextPane();
    document = textPane.getDocument();
    scrollPane = new JScrollPane(textPane);

    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
View Full Code Here

      setBounds(getBounds(args));
      JPanel box = new JPanel();
      // Use BoxLayout.Y_AXIS below if you want a vertical box
      box.setLayout(new GridLayout(1,1));
      setContentPane(box);
      this.pane = new JTextPane();
      this.pane.setBackground(getColor(args));
      JScrollPane pane = new JScrollPane(this.pane);
      // this.pane.setBorder(BorderFactory.createRaisedBevelBorder());
      this.pane.setAutoscrolls(true);
     
View Full Code Here

    JPanel panel = new JPanel();
    frame.setContentPane( panel );
    panel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
    panel.setLayout(new BorderLayout());

    JTextPane textPane = new JTextPane();
    textPane.setFont( new Font("monospaced", Font.PLAIN, 12) );
    textPane.setText("abc");

    JScrollPane scrollPane = new JScrollPane(textPane);
    panel.add(scrollPane);
    scrollPane.setPreferredSize(new Dimension(300, 250));
View Full Code Here

        });

        currentDirectory = new JLabel("not set");
        currentFile = new JLabel("not set");
        progressBar = new JProgressBar();
        messagePane = new JTextPane();
        messagePane.setEditable(false);
        messagePane.setAutoscrolls(true);

        content.add(currentDirectory, new GridBagConstraints(0, 0, 2, 1, 0, 0,
                GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
View Full Code Here

TOP

Related Classes of javax.swing.JTextPane

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.