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


Java StyleConstants.setAlignment方法代碼示例

本文整理匯總了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);
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:35,代碼來源:LicenseWindow.java

示例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...");
}
 
開發者ID:CalebKussmaul,項目名稱:GIFKR,代碼行數:14,代碼來源:UpdateFrame.java

示例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");
    }

}
 
開發者ID:EvilInsultGenerator,項目名稱:desktop,代碼行數:40,代碼來源:Main.java

示例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);
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:16,代碼來源:Utility.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:JViewPortBackingStoreImageTest.java

示例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
  //
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:58,代碼來源:FlowLabel.java

示例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);
}
 
開發者ID:Coder-ACJHP,項目名稱:Hotel-Properties-Management-System,代碼行數:59,代碼來源:ReadLogsWindow.java

示例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);
}
 
開發者ID:CalebKussmaul,項目名稱:GIFKR,代碼行數:7,代碼來源:ViewUtils.java

示例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();
}
 
開發者ID:TeamRedFox,項目名稱:PointOfSale,代碼行數:46,代碼來源:LoginPanel.java


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