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:Main.java

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

    Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" };
    JTree tree = new JTree(array);
    tree.setEditable(true);/*w w  w  . j av a 2  s  .  com*/
    tree.setRootVisible(true);
    JCheckBox checkBox = new JCheckBox();
    TreeCellEditor editor = new DefaultCellEditor(checkBox);
    tree.setCellEditor(editor);

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

From source file:GTKLookAndFeelDemo.java

public static void main(String[] args) {
    try {//from www.  jav  a 2  s  .  co m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    JLabel label = new JLabel("Label");
    JTextField field = new JTextField("www.java2s.com!");
    JList list = new JList(new String[] { "A", "B", "C" });
    JScrollPane listPane = new JScrollPane(list);
    listPane.setPreferredSize(new Dimension(250, 100));

    JScrollPane treePane = new JScrollPane(new JTree());
    treePane.setPreferredSize(new Dimension(250, 100));
    JButton button = new JButton("Click me");

    JPanel cp = new JPanel();
    cp.add(label);
    cp.add(field);
    cp.add(listPane);
    cp.add(treePane);
    cp.add(button);

    JFrame frame = new JFrame();
    frame.setTitle("Windows Look and Feel Demo");
    frame.setPreferredSize(new Dimension(280, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(cp);
    frame.pack();
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    String title = (args.length == 0 ? "TextArea Example" : args[0]);
    JFrame frame = new JFrame(title);
    Container content = frame.getContentPane();

    content.setLayout(new GridLayout(0, 2));

    JTextArea leftTextArea = new JTextArea();
    content.add(leftTextArea);//from   www  .  jav  a  2s.  com
    leftTextArea.paste();

    JTextArea rightTextArea = new JTextArea() {
        public boolean isManagingFocus() {
            return false;
        }
    };
    rightTextArea.paste();

    JScrollPane rightPane = new JScrollPane(rightTextArea);
    content.add(rightPane);

    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("Undo Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    UndoManager manager = new UndoManager();
    textArea.getDocument().addUndoableEditListener(manager);

    JToolBar toolbar = new JToolBar();
    JButton undoButton = new JButton(
            new UndoAction(manager, (String) UIManager.get("AbstractUndoableEdit.undoText")));
    toolbar.add(undoButton);// w  w w . j  a va 2  s.  c o m

    Container content = frame.getContentPane();
    content.add(toolbar, BorderLayout.NORTH);
    content.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);

}

From source file:WindowsLookAndFeelDemo.java

public static void main(String[] args) {
    try {/*w  w  w  .  j  av  a  2s .c o m*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    JLabel label = new JLabel("Label");
    JTextField field = new JTextField("www.java2s.com!");
    JList list = new JList(new String[] { "A", "B", "C" });
    JScrollPane listPane = new JScrollPane(list);
    listPane.setPreferredSize(new Dimension(250, 100));

    JScrollPane treePane = new JScrollPane(new JTree());
    treePane.setPreferredSize(new Dimension(250, 100));
    JButton button = new JButton("Click me");

    JPanel cp = new JPanel();
    cp.add(label);
    cp.add(field);
    cp.add(listPane);
    cp.add(treePane);
    cp.add(button);

    JFrame frame = new JFrame();
    frame.setTitle("Windows Look and Feel Demo");
    frame.setPreferredSize(new Dimension(280, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(cp);
    frame.pack();
    frame.setVisible(true);

}

From source file:TreeEdit.java

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

    Object array[] = { Boolean.TRUE, Boolean.FALSE, "Hello" }; // Hello will map to false
    JTree tree = new JTree(array);
    tree.setEditable(true);//from   www  . j a  va 2  s. c  o m
    tree.setRootVisible(true);

    JCheckBox checkBox = new JCheckBox();

    TreeCellEditor editor = new DefaultCellEditor(checkBox);
    tree.setCellEditor(editor);

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

From source file:Main.java

public static void main(String[] args) {
    JTree tree = new JTree(new TestModel());
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JScrollPane(tree));
    frame.pack();//from   ww w  .  ja va2 s .c  o  m
    frame.setVisible(true);
}

From source file:TreeArraySample.java

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

    Vector oneVector = new NamedVector("One", args);
    Vector twoVector = new NamedVector("Two", new String[] { "Mercury", "Venus", "Mars" });
    Vector threeVector = new NamedVector("Three");
    threeVector.add(System.getProperties());
    threeVector.add(twoVector);//from   w w  w  .j a va2  s .c  o m
    Object rootNodes[] = { oneVector, twoVector, threeVector };
    Vector rootVector = new NamedVector("Root", rootNodes);
    JTree tree = new JTree(rootVector);

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

From source file:Main.java

public static void main(String[] args) throws Exception {
    Object[][] data = { { "A", new Integer(3), new Double(7.23), new Boolean(true) },
            { "J", new Integer(2), new Double(4.64), new Boolean(false) },
            { "S", new Integer(1), new Double(8.81), new Boolean(true) } };

    String[] columns = { "Col", "Col", "Col", "Col" };

    JTable table = new JTable(data, columns);
    JScrollPane scroll = new JScrollPane(table);

    JFrame f = new JFrame();
    f.setContentPane(scroll);/*from   w  w w .  j  av a  2 s  . c  o m*/
    f.pack();

    int x = (int) table.getTableHeader().getSize().getWidth();
    int y = (int) table.getTableHeader().getSize().getHeight() + (int) table.getSize().getHeight();

    BufferedImage bi = new BufferedImage((int) x, (int) y, BufferedImage.TYPE_INT_RGB);

    Graphics g = bi.createGraphics();
    table.getTableHeader().paint(g);
    g.translate(0, table.getTableHeader().getHeight());
    table.paint(g);
    g.dispose();

    JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bi)));
    ImageIO.write(bi, "png", new File("c:/Java_Dev/table.png"));

    System.exit(0);
}

From source file:MainClass.java

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

    JTree tree = new JTree(new String[] { "a", "b", "c" });
    ToolTipManager.sharedInstance().registerComponent(tree);
    TreeCellRenderer renderer = new ToolTipTreeCellRenderer();
    tree.setCellRenderer(renderer);/*from   w w  w .  j a v a 2 s .c o m*/
    JScrollPane scrollPane = new JScrollPane(tree);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}