StyleConstants.setLeftIndent(set, left); StyleConstants.setRightIndent(set, right); pane.setParagraphAttributes(set, false);
JTextPane output = new JTextPane(); SimpleAttributeSet attribs = new SimpleAttributeSet(); StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT); output.setParagraphAttributes(attribs, true);
JTextPane text = new JTextPane(); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setAlignment(attributes, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontFamily(attributes, "Default"); text.setParagraphAttributes(attributes, true); text.setEditable(false); text.setOpaque(false); text.setText("Search\nBy:");
import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; class Demo{ public static void main(String[]args){ SwingUtilities.invokeLater(()->{ JFrame frame=new JFrame("Right-Left"); JTextPane box=new JTextPane(); frame.getContentPane().add(box); SimpleAttributeSet attr = new SimpleAttributeSet(); StyleConstants.setAlignment(attr, StyleConstants.ALIGN_RIGHT); box.setParagraphAttributes(attr, true); frame.setSize(300,200); frame.setLocationByPlatform(true); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }); } }
ta.setParagraphAttributes(set, false);
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n" + "\t200.002\t200.002\t200.002\t200.002\n"
StyleConstants.setAlignment(centerStyle, StyleConstants.ALIGN_CENTER); StyleConstants.setFontFamily(centerStyle, textPane.getFont().getFamily()); textPane.setParagraphAttributes(centerStyle, true);
pane.setParagraphAttributes(ATTRIBS, false);
SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setLineSpacing( sas, -.2f ); _outputPanel.setParagraphAttributes( sas, false ); _outputPanel.setEditable( false ); _outputPanel.setCaretColor( Color.white );
sasPara.addAttribute(HTML.Attribute.ALIGN, a_); if (textLength > 0) parentTextPane.select(caretOffset, caretOffset + textLength); parentTextPane.setParagraphAttributes(sasPara, true); } else if (textLength < 0) { if (sasPara.getAttribute(StyleConstants.NameAttribute) == Tag.IMPLIED) sasPara.addAttribute( StyleConstants.NameAttribute, Tag.P); sasPara.addAttribute(HTML.Attribute.ALIGN, a_); parentTextPane.setParagraphAttributes(sasPara, true); } else { SimpleAttributeSet attribs = new SimpleAttributeSet(); attribs.addAttribute(HTML.Attribute.ALIGN, a_); parentTextPane.setParagraphAttributes(sasPara, true); sasText.addAttribute(p_, attribs); if (textLength > 0) parentTextPane.select(caretOffset, caretOffset + textLength);
AttributeSet aset= tabStyle.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet,tabset); textPane.setParagraphAttributes(aset, false);
private void RebuildStyles() { send(" "); StyleConstants.setAlignment(m_objMainStyle, StyleConstants.ALIGN_LEFT); StyleConstants.setFontFamily(m_objMainStyle, m_objChatterFont.getFamily()); StyleConstants.setFontSize(m_objMainStyle, m_objChatterFont.getSize()); StyleConstants.setSpaceAbove(m_objMainStyle, 2); StyleConstants.setSpaceBelow(m_objMainStyle, 2); send("- Chatter font changed"); send(" "); FontMetrics l_objFM = m_objChatPanel.getFontMetrics(m_objChatterFont); float l_f = (float)l_objFM.stringWidth(BEFORE_CATEGORY + ASLDiceBot.OTHER_CATEGORY + "XXX"); TabStop[] lar_objTabs = new TabStop[10]; // this sucks for(int l_i = 0; l_i < lar_objTabs.length; l_i++) { lar_objTabs[l_i] = new TabStop(l_f * (l_i + 1), TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); } TabSet l_objTabset = new TabSet(lar_objTabs); StyleConstants.setTabSet(m_objMainStyle, new TabSet(new TabStop[0])); StyleConstants.setTabSet(m_objMainStyle, l_objTabset); m_objChatPanel.setParagraphAttributes(m_objMainStyle, true); }
MutableAttributeSet att = new SimpleAttributeSet(); StyleConstants.setAlignment(att, align); this.setParagraphAttributes(att, false); MutableAttributeSet att = new SimpleAttributeSet(); StyleConstants.setFirstLineIndent(att, indent); this.setParagraphAttributes(att, false); MutableAttributeSet att = new SimpleAttributeSet(); StyleConstants.setSpaceAbove(att, space); this.setParagraphAttributes(att, false); MutableAttributeSet att = new SimpleAttributeSet(); StyleConstants.setSpaceBelow(att, space); this.setParagraphAttributes(att, false); MutableAttributeSet att = new SimpleAttributeSet(); StyleConstants.setLineSpacing(att, space); this.setParagraphAttributes(att, false);