Example usage for javax.swing JScrollPane JScrollPane

List of usage examples for javax.swing JScrollPane JScrollPane

Introduction

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

Prototype

public JScrollPane(Component view) 

Source Link

Document

Creates a JScrollPane that displays the contents of the specified component, where both horizontal and vertical scrollbars appear whenever the component's contents are larger than the view.

Usage

From source file:UTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Debugging Drop Zone");
    frame.setSize(500, 300);//w  w  w. j  av a2 s  . c  o m
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextArea jta = new JTextArea();
    frame.getContentPane().add(new JScrollPane(jta));
    UberHandler uh = new UberHandler();
    uh.setOutput(jta);
    jta.setTransferHandler(uh);

    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector<String> rowOne = new Vector<String>();
    rowOne.addElement("Row1-Column1");
    rowOne.addElement("Row1-Column2");
    rowOne.addElement("Row1-Column3");

    Vector<String> rowTwo = new Vector<String>();
    rowTwo.addElement("Row2-Column1");
    rowTwo.addElement("Row2-Column2");
    rowTwo.addElement("Row2-Column3");

    Vector<Vector> rowData = new Vector<Vector>();
    rowData.addElement(rowOne);//from   ww  w  . ja v  a 2  s  . c om
    rowData.addElement(rowTwo);

    Vector<String> columnNames = new Vector<String>();
    columnNames.addElement("Column One");
    columnNames.addElement("Column Two");
    columnNames.addElement("Column Three");
    JTable table = new JTable(rowData, columnNames);

    table.setValueAt("aa", 0, 0);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:MainClass.java

public static void main(final String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
    final String headers[] = { "English", "Digit" };

    TableModel fixedColumnModel = new AbstractTableModel() {
        public int getColumnCount() {
            return 2;
        }/* w w  w.  j ava  2s . c  om*/

        public String getColumnName(int column) {
            return headers[column];
        }

        public int getRowCount() {
            return 3;
        }

        public Object getValueAt(int row, int column) {
            return rows[row][column];
        }
    };

    JFrame frame = new JFrame("Scrollless Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(fixedColumnModel);

    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    frame.add(new JScrollPane(table), BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:JComponentTableCellRenderer.java

public static void main(String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
    JFrame frame = new JFrame("Label Header");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    String headers[] = { "English", "#" };
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Icon redIcon = new ImageIcon("yourFile.gif");
    Icon blueIcon = new ImageIcon("yourFile.gif");

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel blueLabel = new JLabel(headers[0], blueIcon, JLabel.CENTER);
    blueLabel.setBorder(headerBorder);/* w ww . j  a  va2s.  c om*/
    JLabel redLabel = new JLabel(headers[1], redIcon, JLabel.CENTER);
    redLabel.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(blueLabel);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(redLabel);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:JTableFilterDemo.java

public static void main(String[] args) {
    Object[][] data = { { "A", 5 }, { "B", 2 }, { "C", 4 }, { "D", 8 } };
    String columnNames[] = { "Item", "Value" };
    TableModel model = new DefaultTableModel(data, columnNames) {
        public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }// w w  w. j a  v a2  s.  c o m
    };
    JTable table = new JTable(model);

    RowFilter<Object, Object> filter = new RowFilter<Object, Object>() {
        public boolean include(Entry entry) {
            Integer population = (Integer) entry.getValue(1);
            return population.intValue() > 3;
        }
    };

    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    sorter.setRowFilter(filter);
    table.setRowSorter(sorter);
    JScrollPane scrollPane = new JScrollPane(table);
    JFrame frame = new JFrame("Filtering Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:TreeNodeVector.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("JTreeSample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus", "Mars" });
    Vector<Object> v2 = new TreeNodeVector<Object>("Three");
    v2.add(System.getProperties());
    v2.add(v1);/*from  w  w  w.j a va2  s. c o m*/
    Object rootNodes[] = { v1, v2 };
    Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes);
    JTree tree = new JTree(rootVector);
    frame.add(new JScrollPane(tree), BorderLayout.CENTER);

    tree.expandRow(1);
    tree.scrollRowToVisible(2);

    tree.revalidate();

    frame.setSize(300, 300);
    frame.setVisible(true);

}

From source file:RendererSample.java

public static void main(String args[]) {
    Object rows[][] = { { "one", "ichi - \u4E00" }, { "two", "ni - \u4E8C" }, { "three", "san - \u4E09" },
            { "four", "shi - \u56DB" }, { "five", "go - \u4E94" }, { "six", "roku - \u516D" },
            { "seven", "shichi - \u4E03" }, { "eight", "hachi - \u516B" }, { "nine", "kyu - \u4E5D" },
            { "ten", "ju - \u5341" } };
    Object headers[] = { "English", "Japanese" };
    JFrame frame = new JFrame("Renderer Sample");
    JTable table = new JTable(rows, headers);
    TableCellRenderer renderer = new EvenOddRenderer();
    table.setDefaultRenderer(Object.class, renderer);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*from  ww  w  . j av  a 2  s . c  o m*/
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Changed Renderer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTree tree = new JTree();
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();

    renderer.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 32));
    int rowHeight = tree.getRowHeight();
    if (rowHeight <= 0) {
        tree.setRowHeight(rowHeight - 1);
    }//from   ww w  . java 2  s .com

    Color backgroundSelection = renderer.getBackgroundSelectionColor();
    renderer.setBackgroundSelectionColor(Color.blue);
    renderer.setBackgroundNonSelectionColor(backgroundSelection);

    // Swap text colors
    Color textSelection = renderer.getTextSelectionColor();
    renderer.setTextSelectionColor(Color.green);
    renderer.setTextNonSelectionColor(textSelection);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:ShowHTMLViews.java

public static void main(String[] args) {
    try {//  w w  w.  ja va  2s.  c  o m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    try {
        JFrame f = new JFrame("HTML Document View Structure");
        final JEditorPane ep = new JEditorPane(args[0]);
        ep.setEditable(false);
        f.getContentPane().add(new JScrollPane(ep));
        f.setSize(400, 300);
        f.setVisible(true);

        ep.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("page")) {
                    System.out.println("Document:\n");
                    HTMLDocDisplay.displayModel(ep, System.out);
                    System.out.println("\n\nViews:\n");
                    HTMLViewDisplayer.displayViews(ep, System.out);
                }
            }
        });
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
}

From source file:SimpleAttributeBoldItalic.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Simple Attributes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    StyledDocument document = new DefaultStyledDocument();

    SimpleAttributeSet attributes = new SimpleAttributeSet();
    attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
    attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE);

    try {/*  w ww  .j a  v  a 2s  .  co  m*/
        document.insertString(document.getLength(), "Bold, Italic", attributes);
    } catch (BadLocationException badLocationException) {
        System.err.println("Bad insert");
    }

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