Example usage for javax.swing.text TabStop TabStop

List of usage examples for javax.swing.text TabStop TabStop

Introduction

In this page you can find the example usage for javax.swing.text TabStop TabStop.

Prototype

public TabStop(float pos) 

Source Link

Document

Creates a tab at position pos with a default alignment and default leader.

Usage

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);
    }//w  w w  .java 2 s.  c o  m

    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:dataviewer.DataViewer.java

private void cb_tableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_tableActionPerformed
    try {//from w ww .j  a  v a  2 s  . c  o 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());
    }
}

From source file:org.colombbus.tangara.EditorFrame.java

/**
 * This method changes the standard size of a TAB for a given JTextPane.
 *
 * @param the/*from   ww w  .  j  a v a 2 s  .c  o  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 w w.  j  av a  2 s. c o m

    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);
}