Example usage for javax.swing JScrollPane getViewport

List of usage examples for javax.swing JScrollPane getViewport

Introduction

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

Prototype

public JViewport getViewport() 

Source Link

Document

Returns the current JViewport.

Usage

From source file:Main.java

public Main(File dir) {
    setLayout(new BorderLayout());
    JTree tree = new JTree(addNodes(null, projectFile));
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
            System.out.println("You selected " + node);
        }/*from  w w  w .j  a  v a 2s . co m*/
    });

    JScrollPane scrollpane = new JScrollPane();
    scrollpane.getViewport().add(tree);
    add(scrollpane, BorderLayout.CENTER);
}

From source file:ColorTableColumnRenderer.java

public ColorTableColumnRenderer() {
    super("Stocks Table");
    setSize(300, 300);/*from  w w  w .ja v a2 s  . c  om*/

    tableModel = new MyTableModel();

    table = new JTable();
    table.setModel(tableModel);

    DefaultTableCellRenderer renderer = new ColoredTableCellRenderer();
    TableColumn column = new TableColumn(0, 190, renderer, null);
    table.addColumn(column);

    JScrollPane ps = new JScrollPane();
    ps.getViewport().add(table);
    getContentPane().add(ps, BorderLayout.CENTER);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:josejamilena.pfc.analizador.GraficoPorSGBD.java

public GraficoPorSGBD(final String sgbd, final String script) throws ClassNotFoundException, SQLException {

    Map<String, String> res = new TreeMap<String, String>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Statement stmt = null;/*from ww  w .  ja  v a  2s.c om*/
    ResultSet rs = null;
    String consulta = "select tiempo, fecha from estadisticas where tipo=\'" + script + "\' and host_sgbd=\'"
            + sgbd + "\'";
    stmt = App.conn.createStatement();
    rs = stmt.executeQuery(consulta);
    while (rs.next()) {
        res.put(rs.getString(2), rs.getString(1));
    }
    rs.close();
    stmt.close();

    Iterator it = res.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        dataset.setValue(Double.parseDouble(pairs.getValue().toString()), script, pairs.getKey().toString());
    }

    JFreeChart chart = ChartFactory.createBarChart(sgbd, // chart title
            "Hora", // domain axis label
            "Duracin (milisegundos)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    ChartPanel chartPanel = new ChartPanel(chart);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add((new JPanel()).add(chartPanel));
    setContentPane(scrollPane);
}

From source file:FileTree.java

/** Construct a FileTree */
public FileTree(File dir) {
    setLayout(new BorderLayout());

    // Make a tree list with all the nodes, and make it a JTree
    JTree tree = new JTree(addNodes(null, dir));

    // Add a listener
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
            System.out.println("You selected " + node);
        }//from   www. ja va2 s .  c  o  m
    });

    // Lastly, put the JTree into a JScrollPane.
    JScrollPane scrollpane = new JScrollPane();
    scrollpane.getViewport().add(tree);
    add(BorderLayout.CENTER, scrollpane);
}

From source file:josejamilena.pfc.analizador.GraficoPorCliente.java

public GraficoPorCliente(final String cliente, final String script)
        throws ClassNotFoundException, SQLException {

    Map<String, String> res = new TreeMap<String, String>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Statement stmt = null;//w  w  w .ja v  a 2 s.  com
    ResultSet rs = null;
    String consulta = "select tiempo, fecha from estadisticas where tipo=\'" + script + "\' and host_cliente=\'"
            + cliente + "\'";
    stmt = App.conn.createStatement();
    rs = stmt.executeQuery(consulta);
    while (rs.next()) {
        res.put(rs.getString(2), rs.getString(1));
    }
    rs.close();
    stmt.close();

    Iterator it = res.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        dataset.setValue(Double.parseDouble(pairs.getValue().toString()), script, pairs.getKey().toString());
    }

    JFreeChart chart = ChartFactory.createBarChart(cliente, // chart title
            "Hora", // domain axis label
            "Duracin (milisegundos)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    ChartPanel chartPanel = new ChartPanel(chart);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add((new JPanel()).add(chartPanel));
    setContentPane(scrollPane);
}

From source file:josejamilena.pfc.analizador.GraficoPorScript.java

public GraficoPorScript(final String hostCliente, final String hostSgbd)
        throws ClassNotFoundException, SQLException {

    Map<String, String> res = new TreeMap<String, String>();
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Statement stmt = null;//from  w  w w.ja  v  a2 s.  com
    ResultSet rs = null;
    String consulta = "select tiempo, fecha from estadisticas where host_cliente=\'" + hostCliente
            + "\' and host_sgbd=\'" + hostSgbd + "\'";
    stmt = App.conn.createStatement();
    rs = stmt.executeQuery(consulta);
    while (rs.next()) {
        res.put(rs.getString(2), rs.getString(1));
    }
    rs.close();
    stmt.close();

    Iterator it = res.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = (Map.Entry) it.next();
        dataset.setValue(Double.parseDouble(pairs.getValue().toString()), hostCliente,
                pairs.getKey().toString());
    }

    JFreeChart chart = ChartFactory.createBarChart(hostCliente + " / " + hostSgbd, // chart title
            "Hora", // domain axis label
            "Duracin (milisegundos)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    ChartPanel chartPanel = new ChartPanel(chart);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.getViewport().add((new JPanel()).add(chartPanel));
    setContentPane(scrollPane);
}

From source file:Tree1.java

public Tree1() {
    super("Sample Tree [OID]");
    setSize(400, 300);// w ww.java2  s .  com

    Object[] nodes = new Object[5];
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new OidNode(1, "ISO"));
    DefaultMutableTreeNode parent = top;
    nodes[0] = top;

    DefaultMutableTreeNode node = new DefaultMutableTreeNode(new OidNode(0, "standard"));
    parent.add(node);
    node = new DefaultMutableTreeNode(new OidNode(2, "member-body"));
    parent.add(node);
    node = new DefaultMutableTreeNode(new OidNode(3, "org"));
    parent.add(node);
    parent = node;
    nodes[1] = parent;

    node = new DefaultMutableTreeNode(new OidNode(6, "dod"));
    parent.add(node);
    parent = node;
    nodes[2] = parent;

    node = new DefaultMutableTreeNode(new OidNode(1, "internet"));
    parent.add(node);
    parent = node;
    nodes[3] = parent;

    node = new DefaultMutableTreeNode(new OidNode(1, "directory"));
    parent.add(node);
    node = new DefaultMutableTreeNode(new OidNode(2, "mgmt"));
    parent.add(node);
    nodes[4] = node;
    node.add(new DefaultMutableTreeNode(new OidNode(1, "mib-2")));
    node = new DefaultMutableTreeNode(new OidNode(3, "experimental"));
    parent.add(node);
    node = new DefaultMutableTreeNode(new OidNode(4, "private"));
    node.add(new DefaultMutableTreeNode(new OidNode(1, "enterprises")));
    parent.add(node);
    node = new DefaultMutableTreeNode(new OidNode(5, "security"));
    parent.add(node);
    node = new DefaultMutableTreeNode(new OidNode(6, "snmpV2"));
    parent.add(node);
    node = new DefaultMutableTreeNode(new OidNode(7, "mail"));
    parent.add(node);

    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);

    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(new ImageIcon("opened.gif"));
    renderer.setClosedIcon(new ImageIcon("closed.gif"));
    renderer.setLeafIcon(new ImageIcon("leaf.gif"));
    m_tree.setCellRenderer(renderer);

    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);
    TreePath path = new TreePath(nodes);
    m_tree.setSelectionPath(path);

    m_tree.addTreeSelectionListener(new OidSelectionListener());

    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    getContentPane().add(s, BorderLayout.CENTER);

    m_display = new JTextField();
    m_display.setEditable(false);
    getContentPane().add(m_display, BorderLayout.SOUTH);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
}

From source file:TextViewer.java

/**
 * Constructor//ww  w.jav a  2  s  .c o m
 */
public TextViewer() {
    super(new GridLayout(1, 1));

    // create the text area
    text_area = new JTextArea();
    text_area.setEditable(false);
    text_area.setLineWrap(true);

    // create a scroll pane for the JTextArea
    JScrollPane sp = new JScrollPane();
    sp.setPreferredSize(new Dimension(300, 300));
    sp.getViewport().add(text_area);

    add(sp);
}

From source file:TableSortDemo.java

public TableSortDemo() {
    super();/*from  w w  w .j a v  a  2 s . c o  m*/
    setSize(600, 300);

    tableModel = new MyTableModel();

    getContentPane().add(titleLabel, BorderLayout.NORTH);
    table.setModel(tableModel);

    JTableHeader header = table.getTableHeader();
    header.setUpdateTableInRealTime(true);
    header.addMouseListener(tableModel.new ColumnListener(table));
    header.setReorderingAllowed(true);

    JScrollPane ps = new JScrollPane();
    ps.getViewport().add(table);
    getContentPane().add(ps, BorderLayout.CENTER);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:StocksTable.java

public StocksTable() {
    super("Stocks Table");
    setSize(600, 300);// ww  w . j av  a 2  s.  c o  m

    m_data = new StockTableData();

    m_title = new JLabel(m_data.getTitle(), new ImageIcon("money.gif"), SwingConstants.LEFT);
    m_title.setFont(new Font("TimesRoman", Font.BOLD, 24));
    m_title.setForeground(Color.black);
    getContentPane().add(m_title, BorderLayout.NORTH);

    m_table = new JTable();
    m_table.setAutoCreateColumnsFromModel(false);
    m_table.setModel(m_data);

    for (int k = 0; k < StockTableData.m_columns.length; k++) {
        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
        renderer.setHorizontalAlignment(StockTableData.m_columns[k].m_alignment);
        TableColumn column = new TableColumn(k, StockTableData.m_columns[k].m_width, renderer, null);
        m_table.addColumn(column);
    }

    JTableHeader header = m_table.getTableHeader();
    header.setUpdateTableInRealTime(false);

    JScrollPane ps = new JScrollPane();
    ps.getViewport().add(m_table);
    getContentPane().add(ps, BorderLayout.CENTER);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}