本文整理汇总了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);
}