List of usage examples for javax.swing.text StyleContext addAttribute
public synchronized AttributeSet addAttribute(AttributeSet old, Object name, Object value)
From source file:Main.java
public static void main(String... args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.RED); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); JTextPane tPane1 = new JTextPane(); tPane1.setCharacterAttributes(aset, false); f.add(tPane1, BorderLayout.CENTER); f.pack();/*from ww w .j a v a 2 s . co m*/ f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[2]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tValue\n" + "\t200.002\t200.002\t200.002\t200.002\n"); JFrame d = new JFrame(); d.setContentPane(new JScrollPane(pane)); d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); d.setSize(360, 120);// w w w.jav a2s .co m d.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[1]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); 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" + "\t.33\t.33\t.33\t.33\n"); JFrame frame = new JFrame("TabExample"); frame.setContentPane(new JScrollPane(pane)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(360, 120);/*from ww w. j av a 2 s . com*/ frame.setVisible(true); }
From source file:TabExample.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[4]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE); tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); 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" + "\t.33\t.33\t.33\t.33\n"); JFrame frame = new JFrame("TabExample"); frame.setContentPane(new JScrollPane(pane)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(360, 120);/*w w w .j a va2s. com*/ frame.setVisible(true); }
From source file:Main.java
private static void appendToPane(JTextPane tp, String msg, Color f, Color b) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, f); aset = sc.addAttribute(aset, StyleConstants.Background, b); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = tp.getDocument().getLength(); tp.setCaretPosition(len);//from w ww .j a va 2s . co m tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg); }
From source file:Main.java
public void append(Color c, String s) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); int len = getDocument().getLength(); setCaretPosition(len);//from w w w.j a v a 2 s .c o m setCharacterAttributes(aset, false); replaceSelection(s); }
From source file:Main.java
private void appendToPane(JTextPane tp, String msg, Color c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = tp.getDocument().getLength(); tp.setCaretPosition(len);// w w w. j av a 2 s .co m tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg); }
From source file:ParenMatcher.java
public ParenMatcher() { // create an array of AttributeSets from the array of Colors StyleContext sc = StyleContext.getDefaultStyleContext(); badAttrSet = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, badColor); matchAttrSet = new AttributeSet[matchColor.length]; for (int j = 0; j < matchColor.length; j += 1) matchAttrSet[j] = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, matchColor[j]); }
From source file:com.NewJFrame.java
private void appendToPane(JTextPane tp, String msg, Color c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); // aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); // aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = tp.getDocument().getLength(); tp.setCaretPosition(len);/* w w w .ja va2 s . c o m*/ tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg); }
From source file:dataviewer.DataViewer.java
private void cb_tableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_tableActionPerformed try {//from ww w .j a v a 2s .co m table = cb_table.getSelectedItem().toString(); DB db = new DB("./db/" + table + ".db"); db.open(); String[] cols = db.get_table_columns(table); db.close(); DefaultTableModel model = new DefaultTableModel(); //model.addColumn("Column Index"); model.addColumn("Field"); int i = 1; StyleContext sc = StyleContext.getDefaultStyleContext(); TabSet tabs = new TabSet(new TabStop[] { new TabStop(20) }); AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabs); tp_sql.setParagraphAttributes(paraSet, false); StyledDocument doc = tp_sql.getStyledDocument(); doc.remove(0, doc.getLength()); doc.insertString(doc.getLength(), "SELECT", null); doc.insertString(doc.getLength(), "\n", null); for (int j = 1; j < cols.length; ++j) { String s = cols[j]; //model.addRow(new Object[]{i++, s}); model.addRow(new Object[] { s }); doc.insertString(doc.getLength(), "\t", null); doc.insertString(doc.getLength(), s, null); if (j < cols.length - 1) { doc.insertString(doc.getLength(), ",", null); } doc.insertString(doc.getLength(), "\n", null); } doc.insertString(doc.getLength(), "FROM", null); doc.insertString(doc.getLength(), "\n", null); doc.insertString(doc.getLength(), "\t", null); doc.insertString(doc.getLength(), table, null); /*doc.insertString(doc.getLength(), "\n", null); doc.insertString(doc.getLength(), "WHERE", null); doc.insertString(doc.getLength(), "\n", null); doc.insertString(doc.getLength(), "\t", null); doc.insertString(doc.getLength(), "_N_ <= " + N, null); doc.insertString(doc.getLength(), ";", null);*/ tb_columns.setModel(model); TableRowSorter trs = new TableRowSorter(model); trs.setComparator(0, new IntComparator()); tb_columns.setRowSorter(trs); //highline(); } catch (Exception e) { txt_count.setText(e.getMessage()); } }