本文整理汇总了Java中javax.swing.text.StyleConstants.setAlignment方法的典型用法代码示例。如果您正苦于以下问题:Java StyleConstants.setAlignment方法的具体用法?Java StyleConstants.setAlignment怎么用?Java StyleConstants.setAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.StyleConstants
的用法示例。
在下文中一共展示了StyleConstants.setAlignment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LicenseWindow
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* Create the frame.
*/
public LicenseWindow(final String path) {
setTitle("Coder HPMSA - [License]");
setBounds(100, 100, 550, 550);
setBackground(Color.decode("#066d95"));
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setIconImage(Toolkit.getDefaultToolkit().
getImage(getClass().getResource(LOGOPATH)));
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
getContentPane().add(scrollPane, BorderLayout.CENTER);
editorPane = new JTextPane();
editorPane.setBackground(new Color(255, 255, 240));
editorPane.setFont(new Font("Verdana", Font.PLAIN, 13));
editorPane.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
editorPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
editorPane.setEditable(false);
scrollPane.setViewportView(editorPane);
final StyledDocument doc = editorPane.getStyledDocument();
final SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength()-1, center, false);
fillEditorPane(path);
setVisible(true);
}
示例2: initializeComponents
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
private void initializeComponents() {
infoPane = new JTextPane();
infoPane.setText("You are using version "+version+" but the current version is " +CalebKussmaul.getLatestVersion(p)+". It is strongly reccomended that you update to take advantage of the latest additions and fixes.");
StyledDocument doc = infoPane.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
infoPane.setEditable(false);
infoPane.setOpaque(false);
updateButton = new JButton("Download update...");
}
示例3: Main
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* @main
*/
public Main() {
initComponents();
setLocationRelativeTo(this);
this.setTitle("EVIL INSULT GENERATOR");
this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/com/imgs/app-icon.png")));
addCombobox();
AutoCompleteDecorator.decorate(this.cmbLanguage);
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
cmbLanguage.setRenderer(dlcr);
StyledDocument doc = txtPaneShow.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
try {
Document doc1 = Jsoup.connect("http://evilinsult.com/generate_insult.php?lang=en").get();
Elements links = doc1.select("body");
for (Element link : links) {
txtPaneShow.setText("\n" + link.text());
}
} catch (RuntimeException e) {
throw e;
} catch (Exception ex) {
txtPaneShow.setText("Insult Outage! Please Check Your Internet Connection And Try Again In Three Minutes");
}
}
示例4: initStyleContext
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public static void initStyleContext(Font font) {
Style defaultStyle = StyleContext.getDefaultStyleContext()
.getStyle(StyleContext.DEFAULT_STYLE);
STYLE_CONTEXT = new StyleContext();
Style regular = STYLE_CONTEXT.addStyle("regular", defaultStyle);
StyleConstants.setFontFamily(regular, font.getFamily());
StyleConstants.setFontSize(regular, font.getSize());
Style buttonStyle = STYLE_CONTEXT.addStyle("button", regular);
StyleConstants.setForeground(buttonStyle, LINK_COLOR);
Style right = STYLE_CONTEXT.addStyle("right", regular);
StyleConstants.setAlignment(right, StyleConstants.ALIGN_RIGHT);
}
示例5: createStyles
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
static void createStyles() {
styles = new StyleContext();
doc = new DefaultStyledDocument(styles);
contentAttributes = new HashMap<>();
// no attributes defined
Style s = styles.addStyle(null, null);
contentAttributes.put("none", s);
Style def = styles.getStyle(StyleContext.DEFAULT_STYLE);
Style heading = styles.addStyle("heading", def);
StyleConstants.setFontFamily(heading, "SansSerif");
StyleConstants.setBold(heading, true);
StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
StyleConstants.setSpaceAbove(heading, 10);
StyleConstants.setSpaceBelow(heading, 10);
StyleConstants.setFontSize(heading, 18);
// Title
Style sty = styles.addStyle("title", heading);
StyleConstants.setFontSize(sty, 32);
// author
sty = styles.addStyle("author", heading);
StyleConstants.setItalic(sty, true);
StyleConstants.setSpaceBelow(sty, 25);
}
示例6: FlowLabel
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* Creates a <code>FlowLabel</code> with the desired text
* and width.
*
* @param text the text for the label
* @param width the initial width of the label in em
*/
public FlowLabel(String text, int width) {
super();
setEditable(false);
setText(text);
// FIXME: This is a workaround for Redhat Bugzilla Bug #459967:
// JTextPane.setBackground() fails when using GTK LookAndFeel. Once this
// bug is resolved, there is no need to make this component nonopaque.
setOpaque(false);
// set the colors and font a JLabel would have
putClientProperty(HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
setFont(UIManager.getFont("Label.font"));
setForeground(UIManager.getColor("Label.foreground"));
setBackground(UIManager.getColor("Label.background"));
// set full justification for the text
final StyledDocument doc = getStyledDocument();
final SimpleAttributeSet sa = new SimpleAttributeSet();
StyleConstants.setAlignment(sa, StyleConstants.ALIGN_JUSTIFIED);
doc.setParagraphAttributes(0, doc.getLength(), sa, false);
//
// This is a kludge to get around the fact that Swing layouts don't
// support methods like getHeightForWidth(int) and so have no sensible
// way of sizing widgets whose height and width are interdependent.
//
// convert the initial width from em to pixels
final int w = width * getFont().getSize();
// determine the preferred height at the initial width
final Dimension d = new Dimension(w, Integer.MAX_VALUE);
setSize(d);
d.height = getPreferredSize().height;
setPreferredSize(d);
// unset the preferred size once we are laid out the first time
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
setPreferredSize(null);
removeComponentListener(this);
}
});
//
// end of preferred size kludge
//
}
示例7: ReadLogsWindow
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
/**
* Create the frame.
*/
public ReadLogsWindow() {
setTitle("Coder HPMSA - [Read Logs]");
setBounds(100, 100, 660, 550);
setBackground(Color.decode("#066d95"));
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setIconImage(Toolkit.getDefaultToolkit().
getImage(getClass().getResource(LOGOPATH)));
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
getContentPane().add(scrollPane, BorderLayout.CENTER);
editorPane = new JTextPane();
editorPane.setBackground(new Color(255, 255, 240));
editorPane.setFont(new Font("Verdana", Font.PLAIN, 13));
editorPane.setBorder(new EtchedBorder(EtchedBorder.RAISED, null, null));
editorPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
editorPane.setEditable(false);
scrollPane.setViewportView(editorPane);
final JPanel filesPanel = new JPanel();
filesPanel.setPreferredSize(new Dimension(200, 10));
getContentPane().add(filesPanel, BorderLayout.EAST);
filesPanel.setLayout(new BorderLayout(0, 0));
final JScrollPane listScrollPane = new JScrollPane();
listScrollPane.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
listScrollPane.setViewportView(logFilesList());
filesPanel.add(listScrollPane, BorderLayout.CENTER);
final JPanel titlePanel = new JPanel();
titlePanel.setPreferredSize(new Dimension(10, 40));
titlePanel.setBackground(Color.decode("#066d95"));
titlePanel.setAutoscrolls(true);
getContentPane().add(titlePanel, BorderLayout.NORTH);
titlePanel.setLayout(new BorderLayout(0, 0));
final JLabel lblTitle = new JLabel("SYSTEM LOG RECORDS");
lblTitle.setHorizontalTextPosition(SwingConstants.CENTER);
lblTitle.setHorizontalAlignment(SwingConstants.CENTER);
lblTitle.setAutoscrolls(true);
lblTitle.setFont(new Font("Verdana", Font.BOLD, 25));
lblTitle.setForeground(UIManager.getColor("Button.highlight"));
titlePanel.add(lblTitle, BorderLayout.CENTER);
final StyledDocument doc = editorPane.getStyledDocument();
final SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
setVisible(true);
}
示例8: centerText
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public static void centerText(JTextPane pane) {
StyledDocument doc = pane.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
}
示例9: LoginPanel
import javax.swing.text.StyleConstants; //导入方法依赖的package包/类
public LoginPanel() {
JTextPane welcome = new JTextPane();
welcome.setEditable(false);
welcome.setText(message);
welcome.setBackground(this.getBackground());
welcome.setFont(new Font("Arial", Font.BOLD, 16));
//inspired by http://stackoverflow.com/questions/3213045/centering-text-in-a-jtextarea-or-jtextpane-horizontal-text-alignment
//Centering welcome text
StyledDocument doc = welcome.getStyledDocument();
SimpleAttributeSet center = new SimpleAttributeSet();
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
doc.setParagraphAttributes(0, doc.getLength(), center, false);
this.setLayout(new BorderLayout());
this.add(welcome, BorderLayout.NORTH);
JPanel infoPanel = new JPanel();
infoPanel.setLayout(new GridLayout(START_ROWS, START_COLUMNS));
JPanel userPnl = new JPanel();
JLabel userLbl = new JLabel("Username");
userPnl.setLayout(new FlowLayout());
userPnl.add(userLbl);
userPnl.add(usernameTxt);
infoPanel.add(userPnl);
JPanel passPnl = new JPanel();
JLabel passLbl = new JLabel("Password");
passPnl.setLayout(new FlowLayout());
passPnl.add(passLbl);
passPnl.add(passwordTxt);
infoPanel.add(passPnl);
JPanel signInBtnPnl = new JPanel();
signInBtnPnl.add(signInBtn);
infoPanel.add(errorLbl);
infoPanel.add(signInBtnPnl);
infoPanel.add(new JPanel());
this.add(infoPanel, BorderLayout.SOUTH);
addImage();
}