List of usage examples for javax.swing.text StyleConstants setTabSet
public static void setTabSet(MutableAttributeSet a, TabSet tabs)
From source file:Main.java
public static void main(String[] argv) { JTextPane textPane = new JTextPane(); List list = new ArrayList(); TabStop[] tstops = (TabStop[]) list.toArray(new TabStop[0]); TabSet tabs = new TabSet(tstops); Style style = textPane.getLogicalStyle(); StyleConstants.setTabSet(style, tabs); textPane.setLogicalStyle(style);/* w ww.j a v a 2 s . co m*/ }
From source file:TabSample.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Tab Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); //TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL,TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT //"\tBAR\n", "\tCENTER\n", "\t3.14159265\n", "\tLEFT\n", "\tRIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); TabStop tabstop = new TabStop(150, TabStop.ALIGN_BAR, TabStop.LEAD_DOTS); int position = document.getLength(); document.insertString(position, "TabStop.ALIGN_BAR", null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); JTextPane textPane = new JTextPane(document); textPane.setEditable(false);/* w w w . ja va2 s. com*/ JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { JFrame frame = new JFrame("Tab Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); int positions[] = { TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL, TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT }; String strings[] = { "\tTabStop.ALIGN_BAR\n", "\tTabStop.ALIGN_CENTER\n", "\tTabStop.ALIGN_DECIMAL\n", "\tTabStop.ALIGN_LEFT\n", "\tTabStop.ALIGN_RIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); for (int i = 0, n = positions.length; i < n; i++) { TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS); try {/* w ww . ja v a 2 s.co m*/ int position = document.getLength(); document.insertString(position, strings[i], null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); } catch (BadLocationException badLocationException) { System.err.println("Bad Location"); } } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:TextTabSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Tab Attributes"); Container content = frame.getContentPane(); StyledDocument document = new DefaultStyledDocument(); int positions[] = { TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL, TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT }; String strings[] = { "\tBAR\n", "\tCENTER\n", "\t3.14159265\n", "\tLEFT\n", "\tRIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); for (int i = 0, n = positions.length; i < n; i++) { TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS); try {// w ww.jav a 2 s .com int position = document.getLength(); document.insertString(position, strings[i], null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void setTabs(JTextPane textPane, int charactersPerTab) { FontMetrics fm = textPane.getFontMetrics(textPane.getFont()); int charWidth = fm.charWidth('w'); int tabWidth = charWidth * charactersPerTab; TabStop[] tabs = new TabStop[5]; for (int i = 0; i < tabs.length; i++) { int tab = i + 1; tabs[i] = new TabStop(tab * tabWidth); }//from w ww . ja va 2 s . c om TabSet tabSet = new TabSet(tabs); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet); int length = textPane.getDocument().getLength(); textPane.getStyledDocument().setParagraphAttributes(0, length, attributes, false); }
From source file:org.colombbus.tangara.EditorFrame.java
/** * This method changes the standard size of a TAB for a given JTextPane. * * @param the/*from w ww . ja v a 2 s . co m*/ * JTextPane where to apply this method. */ public void setTabSizeOf(JTextPane textPane) { int spacesPerTab = tabSize; FontMetrics fm = textPane.getFontMetrics(textPane.getFont()); int charWidth = fm.charWidth(' '); int tabWidth = charWidth * spacesPerTab; TabStop[] tabStops = new TabStop[200]; for (int j = 0; j < tabStops.length; j++) { int tab = j + 1; tabStops[j] = new TabStop(tab * tabWidth); } TabSet tabSet = new TabSet(tabStops); Style style = textPane.getLogicalStyle(); StyleConstants.setTabSet(style, tabSet); textPane.setLogicalStyle(style); }
From source file:org.geopublishing.atlasViewer.GpCoreUtil.java
public static void setTabs(final JTextPane textPane, final int charactersPerTab) { final FontMetrics fm = textPane.getFontMetrics(textPane.getFont()); final int charWidth = fm.charWidth('w'); final int tabWidth = charWidth * charactersPerTab; final TabStop[] tabs = new TabStop[10]; for (int j = 0; j < tabs.length; j++) { final int tab = j + 1; tabs[j] = new TabStop(tab * tabWidth); }//from w ww .j a va 2 s .com final TabSet tabSet = new TabSet(tabs); final SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setTabSet(attributes, tabSet); final int length = textPane.getDocument().getLength(); textPane.getStyledDocument().setParagraphAttributes(0, length, attributes, false); }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** Builds the UI component displaying the exception.*/ public static JTextPane buildExceptionArea() { StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); JTextPane textPane = new JTextPane(document); textPane.setOpaque(false);// w w w . j ava 2 s .c o m textPane.setEditable(false); // Create one of each type of tab stop List<TabStop> list = new ArrayList<TabStop>(); // Create a left-aligned tab stop at 100 pixels from the left margin float pos = 15; int align = TabStop.ALIGN_LEFT; int leader = TabStop.LEAD_NONE; TabStop tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a right-aligned tab stop at 200 pixels from the left margin pos = 15; align = TabStop.ALIGN_RIGHT; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a center-aligned tab stop at 300 pixels from the left margin pos = 15; align = TabStop.ALIGN_CENTER; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a decimal-aligned tab stop at 400 pixels from the left margin pos = 15; align = TabStop.ALIGN_DECIMAL; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a tab set from the tab stops TabSet tabs = new TabSet(list.toArray(new TabStop[0])); // Add the tab set to the logical style; // the logical style is inherited by all paragraphs Style style = textPane.getLogicalStyle(); StyleConstants.setTabSet(style, tabs); textPane.setLogicalStyle(style); Style debugStyle = document.addStyle("StyleName", null); StyleConstants.setForeground(debugStyle, Color.BLACK); StyleConstants.setFontFamily(debugStyle, "SansSerif"); StyleConstants.setFontSize(debugStyle, 12); StyleConstants.setBold(debugStyle, false); return textPane; }