Example usage for javax.swing JScrollPane revalidate

List of usage examples for javax.swing JScrollPane revalidate

Introduction

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

Prototype

public void revalidate() 

Source Link

Document

Supports deferred automatic layout.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel(new GridBagLayout());
    for (int i = 0; i < 25; i++) {
        JTextField field = new JTextField("Field " + i, 20);
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridy = i;//w  w  w  . j  av  a  2  s. c  o m
        panel.add(field, constraints);
    }
    JScrollPane scrollPane = new JScrollPane(panel);
    JButton removeButton = new JButton("Remove Field");
    removeButton.addActionListener(e -> {
        if (panel.getComponentCount() >= 1) {
            panel.remove(panel.getComponentCount() - 1);
            scrollPane.revalidate();
            scrollPane.repaint();
        }
    });
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(640, 480);
    f.setLocation(200, 200);
    f.getContentPane().add(scrollPane);
    f.getContentPane().add(removeButton, BorderLayout.SOUTH);
    f.setVisible(true);
}

From source file:net.sf.mzmine.chartbasics.graphicsexport.GraphicsExportDialog.java

/**
 * Create the dialog.//from  ww w  . jav a2s .  c  om
 */
public GraphicsExportDialog() {
    final JFrame thisframe = this;
    //
    parameters = new GraphicsExportParameters();
    chartParam = new ChartThemeParameters();
    parametersAndComponents = new HashMap<String, JComponent>();

    String[] formats = parameters.getParameter(GraphicsExportParameters.exportFormat).getChoices();
    chooser.addChoosableFileFilter(new FileTypeFilter(formats, "Export images"));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    //
    setBounds(100, 100, 808, 795);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new MigLayout("", "[][][grow]", "[][][][grow]"));
    {
        StringParameter p = parameters.getParameter(GraphicsExportParameters.path);
        StringComponent txtPath = p.createEditingComponent();
        contentPanel.add(txtPath, "flowx,cell 0 0,growx");
        parametersAndComponents.put(p.getName(), txtPath);
    }
    {
        btnPath = new JButton("Path");
        btnPath.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                choosePath();
            }
        });
        contentPanel.add(btnPath, "cell 1 0");
    }
    {
        StringParameter p = parameters.getParameter(GraphicsExportParameters.filename);
        StringComponent txtFileName = p.createEditingComponent();
        contentPanel.add(txtFileName, "cell 0 1,growx");
        parametersAndComponents.put(p.getName(), txtFileName);
    }
    {
        JLabel lblFilename = new JLabel("filename");
        contentPanel.add(lblFilename, "cell 1 1");
    }
    {
        JPanel pnSettingsLeft = new JPanel();
        pnSettingsLeft.setMinimumSize(new Dimension(260, 260));
        contentPanel.add(pnSettingsLeft, "cell 0 3,grow");
        pnSettingsLeft.setLayout(new BorderLayout(0, 0));
        {

            GridBagPanel pn = new GridBagPanel();
            {
                // add unit
                UserParameter p;
                JComponent comp;
                // add unit
                p = (UserParameter) parameters.getParameter(GraphicsExportParameters.unit);
                comp = p.createEditingComponent();
                comp.setToolTipText(p.getDescription());
                comp.setEnabled(true);
                pn.add(comp, 2, 2);
                parametersAndComponents.put(p.getName(), comp);

                int i = 0;
                // add export settings
                Parameter[] param = parameters.getParameters();
                for (int pi = 3; pi < param.length; pi++) {
                    p = (UserParameter) param[pi];
                    comp = p.createEditingComponent();
                    comp.setToolTipText(p.getDescription());
                    comp.setEnabled(true);
                    pn.add(new JLabel(p.getName()), 0, i);
                    pn.add(comp, 1, i, 1, 1, 1, 1);
                    // add to map
                    parametersAndComponents.put(p.getName(), comp);
                    i++;
                }

                // add separator
                pn.add(new JSeparator(), 0, i, 5, 1, 1, 1, GridBagConstraints.BOTH);
                i++;
                // add Apply theme button
                JButton btnApply2 = new JButton("Apply theme");
                btnApply2.addActionListener(e -> applyTheme());
                pn.add(btnApply2, 0, i, 5, 1, 1, 1, GridBagConstraints.BOTH);
                i++;

                // add chart settings
                param = chartParam.getParameters();
                for (int pi = 0; pi < param.length; pi++) {
                    p = (UserParameter) param[pi];
                    comp = p.createEditingComponent();
                    comp.setToolTipText(p.getDescription());
                    comp.setEnabled(true);
                    pn.add(new JLabel(p.getName()), 0, i);
                    pn.add(comp, 1, i, 4, 1);
                    // add to map
                    parametersAndComponents.put(p.getName(), comp);
                    i++;
                }

                // add listener to master font
                JFontSpecs master = (JFontSpecs) parametersAndComponents
                        .get(chartParam.getParameter(ChartThemeParameters.masterFont).getName());
                master.addListener(fspec -> {
                    if (listenersEnabled)
                        handleMasterFontChanged(fspec);
                });
            }

            JScrollPane scrollPane = new JScrollPane(pn);
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            pnSettingsLeft.add(scrollPane, BorderLayout.CENTER);
            scrollPane.getVerticalScrollBar().setUnitIncrement(18);
            scrollPane.revalidate();
            scrollPane.repaint();
        }
    }
    {
        {
            pnChartPreview = new JPanel();
            pnChartPreview.setLayout(null);
            contentPanel.add(pnChartPreview, "cell 1 3 2 1,grow");
        }
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("Save");
            okButton.addActionListener(e -> saveGraphicsAs());
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            btnRenewPreview = new JButton("Renew Preview");
            btnRenewPreview.addActionListener(e -> renewPreview());
            buttonPane.add(btnRenewPreview);
        }
        {
            btnApply = new JButton("Apply theme");
            btnApply.addActionListener(e -> applyTheme());
            buttonPane.add(btnApply);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(e -> setVisible(false));
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }
    // set all to components
    updateComponentsFromParameters();
}

From source file:shuffle.fwk.service.roster.EditRosterService.java

@SuppressWarnings("serial")
private Component makeCenterPanel() {
    rosterEntryPanel = new JPanel(new WrapLayout()) {
        // Fix to make it play nice with the scroll bar.
        @Override/*from  w w  w.  jav  a  2 s . c o m*/
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width = (int) (d.getWidth() - 20);
            return d;
        }
    };
    final JScrollPane ret = new JScrollPane(rosterEntryPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    ret.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            ret.revalidate();
        }
    });
    ret.getVerticalScrollBar().setUnitIncrement(27);
    return ret;
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

@SuppressWarnings("serial")
private Component makeTeamPanel() {

    JPanel firstOptionRow = new JPanel(new GridBagLayout());
    GridBagConstraints rowc = new GridBagConstraints();
    rowc.fill = GridBagConstraints.HORIZONTAL;
    rowc.weightx = 0.0;/*w w w.  j  a v a2 s  .c  om*/
    rowc.weighty = 0.0;

    rowc.weightx = 1.0;
    rowc.gridx = 1;
    stageChooser = new StageChooser(this);
    firstOptionRow.add(stageChooser, rowc);
    rowc.weightx = 0.0;

    JPanel secondOptionRow = new JPanel(new GridBagLayout());

    rowc.gridx = 1;
    JLabel megaLabel = new JLabel(getString(KEY_MEGA_LABEL));
    megaLabel.setToolTipText(getString(KEY_MEGA_TOOLTIP));
    secondOptionRow.add(megaLabel, rowc);

    rowc.gridx = 2;
    megaChooser = new JComboBox<String>();
    megaChooser.setToolTipText(getString(KEY_MEGA_TOOLTIP));
    secondOptionRow.add(megaChooser, rowc);

    rowc.gridx = 3;
    JPanel progressPanel = new JPanel(new BorderLayout());
    megaActive = new JCheckBox(getString(KEY_ACTIVE));
    megaActive.setSelected(false);
    megaActive.setToolTipText(getString(KEY_ACTIVE_TOOLTIP));
    progressPanel.add(megaActive, BorderLayout.WEST);
    megaProgressChooser = new JComboBox<Integer>();
    progressPanel.add(megaProgressChooser, BorderLayout.EAST);
    megaProgressChooser.setToolTipText(getString(KEY_MEGA_PROGRESS_TOOLTIP));
    secondOptionRow.add(progressPanel, rowc);

    JPanel thirdOptionRow = new JPanel(new GridBagLayout());

    rowc.gridx = 1;
    JButton clearTeamButton = new JButton(getString(KEY_CLEAR_TEAM));
    clearTeamButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            clearTeam();
        }
    });
    clearTeamButton.setToolTipText(getString(KEY_CLEAR_TEAM_TOOLTIP));
    thirdOptionRow.add(clearTeamButton, rowc);

    rowc.gridx = 2;
    woodCheckBox = new JCheckBox(getString(KEY_WOOD));
    woodCheckBox.setToolTipText(getString(KEY_WOOD_TOOLTIP));
    thirdOptionRow.add(woodCheckBox, rowc);

    rowc.gridx = 3;
    metalCheckBox = new JCheckBox(getString(KEY_METAL));
    metalCheckBox.setToolTipText(getString(KEY_METAL_TOOLTIP));
    thirdOptionRow.add(metalCheckBox, rowc);

    rowc.gridx = 4;
    coinCheckBox = new JCheckBox(getString(KEY_COIN));
    coinCheckBox.setToolTipText(getString(KEY_COIN_TOOLTIP));
    thirdOptionRow.add(coinCheckBox, rowc);

    rowc.gridx = 5;
    freezeCheckBox = new JCheckBox(getString(KEY_FREEZE));
    freezeCheckBox.setToolTipText(getString(KEY_FREEZE_TOOLTIP));
    thirdOptionRow.add(freezeCheckBox, rowc);

    JPanel topPart = new JPanel(new GridBagLayout());
    GridBagConstraints topC = new GridBagConstraints();
    topC.fill = GridBagConstraints.HORIZONTAL;
    topC.weightx = 0.0;
    topC.weighty = 0.0;
    topC.gridx = 1;
    topC.gridy = 1;
    topC.gridwidth = 1;
    topC.gridheight = 1;
    topC.anchor = GridBagConstraints.CENTER;

    topC.gridy = 1;
    topPart.add(firstOptionRow, topC);
    topC.gridy = 2;
    topPart.add(secondOptionRow, topC);
    topC.gridy = 3;
    topPart.add(thirdOptionRow, topC);

    addOptionListeners();

    teamPanel = new JPanel(new WrapLayout()) {
        // Fix to make it play nice with the scroll bar.
        @Override
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width = (int) (d.getWidth() - 20);
            return d;
        }
    };
    final JScrollPane scrollPane = new JScrollPane(teamPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) {
        @Override
        public Dimension getMinimumSize() {
            Dimension d = super.getMinimumSize();
            d.width = topPart.getMinimumSize().width;
            d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height;
            return d;
        }

        @Override
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width = topPart.getMinimumSize().width;
            d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height;
            return d;
        }
    };
    scrollPane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            scrollPane.revalidate();
        }
    });
    scrollPane.getVerticalScrollBar().setUnitIncrement(27);

    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints rc = new GridBagConstraints();
    rc.fill = GridBagConstraints.VERTICAL;
    rc.weightx = 0.0;
    rc.weighty = 0.0;
    rc.gridx = 1;
    rc.gridy = 1;
    rc.insets = new Insets(5, 5, 5, 5);
    ret.add(topPart, rc);
    rc.gridy += 1;
    rc.weightx = 0.0;
    rc.weighty = 1.0;
    rc.insets = new Insets(0, 0, 0, 0);
    ret.add(scrollPane, rc);
    return ret;
}

From source file:utybo.branchingstorytree.swing.editor.StoryNodesEditor.java

public StoryNodesEditor() {
    setLayout(new MigLayout("", "[:33%:300px][grow 150]", "[grow][]"));

    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    add(scrollPane, "cell 0 0,grow");

    jlist = new JList<>();
    jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jlist.setCellRenderer(new SubstanceDefaultListCellRenderer() {

        @Override//from  w  ww. j ava2  s. c  o m
        public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") JList list, Object o,
                int index, boolean isSelected, boolean cellHasFocus) {
            JLabel label = (JLabel) super.getListCellRendererComponent(list, o, index, isSelected,
                    cellHasFocus);

            if (o instanceof StorySingleNodeEditor) {
                if (((StorySingleNodeEditor) o).getStatus() == Status.ERROR)
                    label.setForeground(Color.RED.darker());
                if (o instanceof StoryLogicalNodeEditor)
                    label.setIcon(new ImageIcon(Icons.getImage("LogicalNode", 16)));
                else if (o instanceof StoryTextNodeEditor)
                    label.setIcon(new ImageIcon(Icons.getImage("TextNode", 16)));
                else if (o instanceof StoryVirtualNodeEditor)
                    label.setIcon(new ImageIcon(Icons.getImage("VirtualNode", 16)));
            }

            return label;
        }

    });
    jlist.addListSelectionListener(e -> {
        if (jlist.getSelectedValue() instanceof JComponent) {
            container.removeAll();
            container.add(jlist.getSelectedValue());
            container.revalidate();
            container.repaint();
        }
    });

    JScrollablePanel pan = new JScrollablePanel(new BorderLayout(0, 0));
    jlist.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            scrollPane.revalidate();
            pan.revalidate();
            jlist.revalidate();

            revalidate();
            repaint();
        }

    });
    pan.setScrollableWidth(ScrollableSizeHint.FIT);
    pan.setScrollableHeight(ScrollableSizeHint.STRETCH);
    pan.add(jlist, BorderLayout.CENTER);
    scrollPane.setViewportView(pan);

    container = new JPanel();
    add(container, "cell 1 0,grow");
    container.setLayout(new BorderLayout(0, 0));

    container.add(new JPanel(), BorderLayout.CENTER); // TODO

    JPanel panel = new JPanel();
    add(panel, "cell 0 1 2 1,alignx leading,growy");

    JButton btnAddNode = new JButton(Lang.get("editor.panel.add"),
            new ImageIcon(Icons.getImage("Add Subnode", 16)));
    btnAddNode.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            createMenu().show(btnAddNode, e.getX(), e.getY());
        }
    });
    panel.add(btnAddNode);

    JButton btnRemoveNode = new JButton(Lang.get("editor.panel.remove"),
            new ImageIcon(Icons.getImage("Delete Subnode", 16)));
    btnRemoveNode.addActionListener(e -> removeNode());
    panel.add(btnRemoveNode);

}