當前位置: 首頁>>代碼示例>>Java>>正文


Java JTextArea.setAlignmentX方法代碼示例

本文整理匯總了Java中javax.swing.JTextArea.setAlignmentX方法的典型用法代碼示例。如果您正苦於以下問題:Java JTextArea.setAlignmentX方法的具體用法?Java JTextArea.setAlignmentX怎麽用?Java JTextArea.setAlignmentX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JTextArea的用法示例。


在下文中一共展示了JTextArea.setAlignmentX方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Query

import javax.swing.JTextArea; //導入方法依賴的package包/類
/** Construct a panel with no entries in it.
 */
public Query() {
    _grid = new GridBagLayout();
    _constraints = new GridBagConstraints();
    _constraints.fill = GridBagConstraints.HORIZONTAL;

    // If the next line is commented out, then the PtolemyApplet
    // model parameters will have an entry that is less than one
    // character wide unless the window is made to be fairly large.
    _constraints.weightx = 1.0;
    _constraints.anchor = GridBagConstraints.NORTHWEST;
    _entryPanel.setLayout(_grid);
    // It's not clear whether the following has any real significance...
    // _entryPanel.setOpaque(true);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    _entryPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    // Add a message panel into which a message can be placed using
    // setMessage().
    _messageArea = new JTextArea("");
    _messageArea.setFont(new Font("SansSerif", Font.PLAIN, 12));
    _messageArea.setEditable(false);
    _messageArea.setLineWrap(true);
    _messageArea.setWrapStyleWord(true);

    // It seems like setLineWrap is somewhat broken.  Really,
    // setLineWrap works best with scrollbars.  We have
    // a couple of choices: use scrollbars or hack in something
    // that guesses the number of lines.  Note that to
    // use scrollbars, the tutorial at
    // http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html#textarea
    // suggests: "If you put a text area in a scroll pane, be
    // sure to set the scroll pane's preferred size or use a
    // text area constructor that sets the number of rows and
    // columns for the text area."

    _messageArea.setBackground(null);

    _messageArea.setAlignmentX(Component.LEFT_ALIGNMENT);

    _messageScrollPane = new JScrollPane(_messageArea);
    _messageScrollPane.setVerticalScrollBarPolicy(
        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    // Get rid of the border.
    _messageScrollPane.setBorder(BorderFactory.createEmptyBorder());
    _messageScrollPane.getViewport().setBackground(null);

    // Useful for debugging:
    //_messageScrollPane.setBorder(
    //                    BorderFactory.createLineBorder(Color.pink));

    // We add the _messageScrollPane when we first use it.

    _entryScrollPane = new JScrollPane(_entryPanel);
    // Get rid of the border.
    _entryScrollPane.setBorder(BorderFactory.createEmptyBorder());
    _entryScrollPane.getViewport().setBackground(null);
    _entryScrollPane.setBackground(null);
    add(_entryScrollPane);

    // Setting the background to null allegedly means it inherits the
    // background color from the container.
    _entryPanel.setBackground(null);
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:68,代碼來源:Query.java


注:本文中的javax.swing.JTextArea.setAlignmentX方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。