Example usage for javax.swing JScrollPane setPreferredSize

List of usage examples for javax.swing JScrollPane setPreferredSize

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:statistic.graph.Controller.java

private void createChartOrTable(DiagramData diagram) {
    if (diagram.getType() == DiagramType.TABLE) {
        JTable table = createTable(diagram);
        JScrollPane pane = new JScrollPane(table);
        pane.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300));
        tableScrollPanes.put(diagram, pane);
        contentPane.add(pane);/*  ww w . ja  v a 2s . c o  m*/
    } else {
        ChartPanel chartPanel = createChartPanel(diagram);
        chartPanels.put(diagram, chartPanel);
        contentPane.add(chartPanel);
    }
}

From source file:statistic.graph.Controller.java

private void createChartOrTable(DiagramData diagram, int index) {
    if (diagram.getType() == DiagramType.TABLE) {
        JTable table = createTable(diagram);
        JScrollPane pane = new JScrollPane(table);
        pane.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300));
        tableScrollPanes.put(diagram, pane);
        contentPane.add(pane, index);/*from  w  w w .j  a v  a 2 s .  c o m*/
    } else {
        ChartPanel chartPanel = createChartPanel(diagram);
        chartPanels.put(diagram, chartPanel);
        contentPane.add(chartPanel, index);
    }
}

From source file:de.codesourcery.eve.skills.ui.components.impl.ItemChooserComponent.java

@Override
protected JPanel createPanelHook() {

    tree.setRootVisible(false);//from w  w  w  .j  av  a2s  . c o  m
    tree.setCellRenderer(treeRenderer);

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() != 2 || e.isPopupTrigger()) {
                return;
            }

            final TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
            final ITreeNode node = (ITreeNode) path.getLastPathComponent();

            if (node.getValue() instanceof InventoryType) {
                final InventoryType selectedItem = (InventoryType) node.getValue();
                selectedItemsModel.addItem(selectedItem);
                if (selectionMode == SelectionMode.SINGLE_SELECTION) {
                    okButtonClicked();
                } else if (selectionMode == SelectionMode.MULTIPLE_SELECTION) {
                    // ok
                } else {
                    throw new RuntimeException("Unhandled mode " + selectionMode);
                }
            }
        }
    });

    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            handleTreeExpansion(event);
        }
    });

    final JScrollPane pane = new JScrollPane(tree);
    pane.setPreferredSize(new Dimension(400, 400));

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());

    switch (selectionMode) {
    case SINGLE_SELECTION:
        result.add(pane, constraints().useRemainingSpace().resizeBoth().end());
        break;
    case MULTIPLE_SELECTION:
        result.add(pane, constraints(0, 0).useRelativeWidth().resizeBoth().end());
        result.add(createListViewPanel(), constraints(1, 0).useRemainingWidth().resizeBoth().end());
        break;
    default:
        throw new RuntimeException("Unhandled selection mode" + selectionMode);
    }

    return result;
}

From source file:TextComponentDemo.java

public TextComponentDemo() {
    super("TextComponentDemo");

    //Create the text pane and configure it.
    textPane = new JTextPane();
    textPane.setCaretPosition(0);/*from   w w w .  jav a  2s  .  c o  m*/
    textPane.setMargin(new Insets(5, 5, 5, 5));
    StyledDocument styledDoc = textPane.getStyledDocument();
    if (styledDoc instanceof AbstractDocument) {
        doc = (AbstractDocument) styledDoc;
        doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));
    } else {
        System.err.println("Text pane's document isn't an AbstractDocument!");
        System.exit(-1);
    }
    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(200, 200));

    //Create the text area for the status log and configure it.
    changeLog = new JTextArea(5, 30);
    changeLog.setEditable(false);
    JScrollPane scrollPaneForLog = new JScrollPane(changeLog);

    //Create a split pane for the change log and the text area.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog);
    splitPane.setOneTouchExpandable(true);

    //Create the status area.
    JPanel statusPane = new JPanel(new GridLayout(1, 1));
    CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status");
    statusPane.add(caretListenerLabel);

    //Add the components.
    getContentPane().add(splitPane, BorderLayout.CENTER);
    getContentPane().add(statusPane, BorderLayout.PAGE_END);

    //Set up the menu bar.
    createActionTable(textPane);
    JMenu editMenu = createEditMenu();
    JMenu styleMenu = createStyleMenu();
    JMenuBar mb = new JMenuBar();
    mb.add(editMenu);
    mb.add(styleMenu);
    setJMenuBar(mb);

    //Add some key bindings.
    addBindings();

    //Put the initial text into the text pane.
    initDocument();

    //Start watching for undoable edits and caret changes.
    doc.addUndoableEditListener(new MyUndoableEditListener());
    textPane.addCaretListener(caretListenerLabel);
    doc.addDocumentListener(new MyDocumentListener());
}

From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformHistogramChart.java

protected void setMixPanel() {

    dataPanel2.removeAll();//from   www.j  a va  2  s. co m
    graphPanel2.removeAll();

    chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, CHART_SIZE_Y * 2 / 3));
    graphPanel2.add(chartPanel);
    graphPanel2.validate();

    dataPanel2.add(new JLabel(" "));
    dataPanel2.add(new JLabel("Data"));
    JScrollPane dt = new JScrollPane(dataTable);
    dt.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y * 3 / 8));

    dataPanel2.add(dt);
    JScrollPane st = new JScrollPane(summaryPanel);
    st.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 6));
    dataPanel2.add(st);
    st.validate();

    dataPanel2.add(new JLabel(" "));
    dataPanel2.add(new JLabel("Mapping"));
    mapPanel.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 2));
    dataPanel2.add(mapPanel);

    dataPanel2.validate();

    mixPanel.removeAll();
    mixPanel.add(graphPanel2, BorderLayout.WEST);
    mixPanel.add(new JScrollPane(dataPanel2), BorderLayout.CENTER);
    mixPanel.validate();
}

From source file:gtu._work.ui.SqlCreaterUI.java

private void initGUI() {
    try {/*from ww  w .ja  v a2s.c  om*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jPanel2 = new JPanel();
                    jPanel1.add(jPanel2, BorderLayout.NORTH);
                    jPanel2.setPreferredSize(new java.awt.Dimension(582, 112));
                    {
                        jLabel1 = new JLabel();
                        jPanel2.add(jLabel1);
                        jLabel1.setText("SQL");
                    }
                    {
                        JScrollPane jScrollPane2 = new JScrollPane();
                        jPanel2.add(jScrollPane2);
                        jScrollPane2.setPreferredSize(new java.awt.Dimension(524, 57));
                        {
                            sqlArea = new JTextArea();
                            jScrollPane2.setViewportView(sqlArea);
                        }
                    }
                    {
                        jLabel2 = new JLabel();
                        jPanel2.add(jLabel2);
                        jLabel2.setText("\u4f86\u6e90\u6a94\u8def\u5f91");
                    }
                    {
                        excelFilePathText = new JTextField();
                        JCommonUtil.jTextFieldSetFilePathMouseEvent(excelFilePathText, false);
                        jPanel2.add(excelFilePathText);
                        excelFilePathText.setPreferredSize(new java.awt.Dimension(455, 22));
                    }
                }
                {
                    executeBtn = new JButton();
                    jPanel1.add(executeBtn, BorderLayout.SOUTH);
                    executeBtn.setText("\u7522\u751f");
                    executeBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            executeBtnPreformed();
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(582, 221));
                    {
                        JScrollPane jScrollPane3 = new JScrollPane();
                        jScrollPane1.setViewportView(jScrollPane3);
                        {
                            logArea = new JTextArea();
                            jScrollPane3.setViewportView(logArea);
                        }
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                FlowLayout jPanel3Layout = new FlowLayout();
                jTabbedPane1.addTab("jPanel3", null, jPanel3, null);
                jPanel3.setLayout(jPanel3Layout);
                {
                    jLabel4 = new JLabel();
                    jPanel3.add(jLabel4);
                    jLabel4.setText("Table\u540d\u7a31");
                }
                {
                    tableNameText = new JTextField();
                    jPanel3.add(tableNameText);
                    tableNameText.setPreferredSize(new java.awt.Dimension(463, 23));
                }
                {
                    jLabel3 = new JLabel();
                    jPanel3.add(jLabel3);
                    jLabel3.setText("\u4f86\u6e90\u6a94\u8def\u5f91");
                }
                {
                    excelFilePathText2 = new JTextField();
                    JCommonUtil.jTextFieldSetFilePathMouseEvent(excelFilePathText2, false);
                    jPanel3.add(excelFilePathText2);
                    excelFilePathText2.setPreferredSize(new java.awt.Dimension(455, 22));
                }
                {
                    firstRowMakeInsertSqlBtn = new JButton();
                    jPanel3.add(firstRowMakeInsertSqlBtn);
                    firstRowMakeInsertSqlBtn.setText(
                            "\u4ee5\u7b2c\u4e00\u5217\u70ba\u6b04\u4f4d\u540d\u7a31\u7522\u751fInsert SQL");
                    firstRowMakeInsertSqlBtn.setPreferredSize(new java.awt.Dimension(251, 22));
                    firstRowMakeInsertSqlBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            firstRowMakeInsertSqlBtn(evt);
                        }
                    });
                }
            }
        }
        pack();
        this.setSize(595, 409);
    } catch (Exception e) {
        // add your error handling code here
        e.printStackTrace();
    }
}

From source file:edu.ucla.stat.SOCR.chart.SuperAreaChart_XY.java

protected void setChart() {
    // update graph
    //   System.out.println("setChart called");

    graphPanel.removeAll();//from  w ww  .ja v  a 2  s .  c  o m
    graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));

    chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y));

    if (legendPanelOn) {
        JFreeChart chart2 = createLegendChart(createLegend(dataset));
        legendPanel = new ChartPanel(chart2, false);
        //legendPanel.setPreferredSize(new Dimension(CHART_SIZE_X,CHART_SIZE_Y*2/3));
    }

    graphPanel.add(chartPanel);
    JScrollPane legendPane = new JScrollPane(legendPanel);
    if (legendPanelOn) {
        legendPane.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y / 5));
        graphPanel.add(legendPane);
    }

    graphPanel.validate();

    // get the GRAPH panel to the front
    if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) {
        tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel));
        graphPanel.removeAll();
        graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));

        graphPanel.add(chartPanel);

        if (legendPanelOn) {
            legendPane = new JScrollPane(legendPanel);
            legendPane.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y / 5));
            graphPanel.add(legendPane);
        }
        graphPanel.validate();
    } else {
        graphPanel2.removeAll();
        chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, CHART_SIZE_Y * 2 / 3));
        //   legendPanel.setPreferredSize(new Dimension(CHART_SIZE_X*2/3,CHART_SIZE_Y*2/5));
        graphPanel2.add(chartPanel);
        if (legendPanelOn) {
            legendPane = new JScrollPane(legendPanel);
            legendPane.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, CHART_SIZE_Y * 2 / 5));
            graphPanel2.add(legendPane);
        }
        graphPanel2.validate();
        summaryPanel.validate();
    }
}

From source file:com.offbynull.peernetic.debug.visualizer.JGraphXVisualizer.java

/**
 * Creates a {@link JGraphXVisualizer} object.
 *//*w w w . j a  v a  2 s . c  om*/
public JGraphXVisualizer() {

    graph = new mxGraph();
    graph.setCellsEditable(false);
    graph.setAllowDanglingEdges(false);
    graph.setAllowLoops(false);
    graph.setCellsDeletable(false);
    graph.setCellsCloneable(false);
    graph.setCellsDisconnectable(false);
    graph.setDropEnabled(false);
    graph.setSplitEnabled(false);
    graph.setCellsBendable(false);
    graph.setConnectableEdges(false);
    graph.setCellsMovable(false);
    graph.setCellsResizable(false);
    graph.setAutoSizeCells(true);

    component = new mxGraphComponent(graph);
    component.setConnectable(false);

    component.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    component.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

    nodeLookupMap = new DualHashBidiMap<>();
    connToEdgeLookupMap = new MultiValueMap<>();
    edgeToConnLookupMap = new HashMap<>();
    vertexLingerTriggerMap = new HashMap<>();

    textOutputArea = new JTextArea();
    textOutputArea.setLineWrap(false);
    textOutputArea.setEditable(false);
    JScrollPane textOutputScrollPane = new JScrollPane(textOutputArea);
    textOutputScrollPane.setPreferredSize(new Dimension(0, 100));

    frame = new JFrame("Visualizer");
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, component, textOutputScrollPane);
    splitPane.setResizeWeight(1.0);

    frame.setContentPane(splitPane);

    component.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            zoomFit();
        }
    });

    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            Recorder<A> rec = recorder.get();
            if (rec != null) {
                IOUtils.closeQuietly(rec);
            }

            VisualizerEventListener veListener = listener.get();
            if (veListener != null) {
                veListener.closed();
            }
        }
    });

    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    splitPane.setDividerLocation(0.2);
}

From source file:TextComponentDemo.java

public TextComponentDemo() {
    super("TextComponentDemo");

    // Create the text pane and configure it.
    textPane = new JTextPane();
    textPane.setCaretPosition(0);/*  ww w.jav a2  s .co m*/
    textPane.setMargin(new Insets(5, 5, 5, 5));
    StyledDocument styledDoc = textPane.getStyledDocument();
    if (styledDoc instanceof AbstractDocument) {
        doc = (AbstractDocument) styledDoc;
        doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));
    } else {
        System.err.println("Text pane's document isn't an AbstractDocument!");
        System.exit(-1);
    }
    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(200, 200));

    // Create the text area for the status log and configure it.
    changeLog = new JTextArea(5, 30);
    changeLog.setEditable(false);
    JScrollPane scrollPaneForLog = new JScrollPane(changeLog);

    // Create a split pane for the change log and the text area.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog);
    splitPane.setOneTouchExpandable(true);

    // Create the status area.
    JPanel statusPane = new JPanel(new GridLayout(1, 1));
    CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status");
    statusPane.add(caretListenerLabel);

    // Add the components.
    getContentPane().add(splitPane, BorderLayout.CENTER);
    getContentPane().add(statusPane, BorderLayout.PAGE_END);

    // Set up the menu bar.
    actions = createActionTable(textPane);
    JMenu editMenu = createEditMenu();
    JMenu styleMenu = createStyleMenu();
    JMenuBar mb = new JMenuBar();
    mb.add(editMenu);
    mb.add(styleMenu);
    setJMenuBar(mb);

    // Add some key bindings.
    addBindings();

    // Put the initial text into the text pane.
    initDocument();
    textPane.setCaretPosition(0);

    // Start watching for undoable edits and caret changes.
    doc.addUndoableEditListener(new MyUndoableEditListener());
    textPane.addCaretListener(caretListenerLabel);
    doc.addDocumentListener(new MyDocumentListener());
}

From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java

private void initialize() {
    JScrollPane tableScrollPane = new JScrollPane(monitorTable);
    tableScrollPane.setPreferredSize(new Dimension(300, 300));
    JScrollPane transactionTypesScrollPane = new JScrollPane();
    leftDockPanel = new JPanel();
    leftDockPanel.setLayout(new MigLayout("fill"));
    transactionTypesPanel = new JPanel();
    transactionTypesPanel.setLayout(new MigLayout("wrap 3"));
    rightPanel = new JPanel();
    rightPanel.setLayout(new MigLayout("fill"));
    rightPanel.setPreferredSize(new Dimension(640, 480));

    transactionTypesScrollPane.setViewportView(transactionTypesPanel);
    transactionTypesScrollPane.setBorder(BorderFactory.createTitledBorder("Transaction types"));
    transactionTypesScrollPane.setPreferredSize(new Dimension(360, 300));

    throughputCollection = new TimeSeriesCollection();
    throughputChartPanel = new ChartPanel(createThroughputChart(throughputCollection));

    latencyCollection = new TimeSeriesCollection();
    latencyChartPanel = new ChartPanel(createAverageLatencyChart(latencyCollection));

    leftDockPanel.add(tableScrollPane, "wrap, grow");
    leftDockPanel.add(transactionTypesScrollPane, "grow");

    rightPanel.add(throughputChartPanel, "grow, wrap");
    rightPanel.add(latencyChartPanel, "grow");

    this.add(leftDockPanel, "dock west, growy");
    this.add(rightPanel, "grow");
}