Example usage for javax.swing.event ChangeListener ChangeListener

List of usage examples for javax.swing.event ChangeListener ChangeListener

Introduction

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

Prototype

ChangeListener

Source Link

Usage

From source file:UndoExample5.java

public UndoExample5() {
    super("Undo/Redo Example 5");

    pane = new JTextPane();
    pane.setEditable(true); // Editable
    getContentPane().add(new JScrollPane(pane), BorderLayout.CENTER);

    // Add a menu bar
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);/*from   w w  w  .  j  a v  a 2 s.  c om*/

    // Populate the menu bar
    createMenuBar();

    // Create the undo manager and actions
    MonitorableUndoManager manager = new MonitorableUndoManager();
    pane.getDocument().addUndoableEditListener(manager);

    Action undoAction = new UndoAction(manager);
    Action redoAction = new RedoAction(manager);

    // Add the actions to buttons
    JPanel panel = new JPanel();
    final JButton undoButton = new JButton("Undo");
    final JButton redoButton = new JButton("Redo");
    undoButton.addActionListener(undoAction);
    redoButton.addActionListener(redoAction);

    undoButton.setEnabled(false);
    redoButton.setEnabled(false);
    panel.add(undoButton);
    panel.add(redoButton);
    getContentPane().add(panel, BorderLayout.SOUTH);

    // Assign the actions to keys
    pane.registerKeyboardAction(undoAction, KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK),
            JComponent.WHEN_FOCUSED);
    pane.registerKeyboardAction(redoAction, KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK),
            JComponent.WHEN_FOCUSED);

    // Handle events from the MonitorableUndoManager
    manager.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            MonitorableUndoManager m = (MonitorableUndoManager) evt.getSource();
            boolean canUndo = m.canUndo();
            boolean canRedo = m.canRedo();

            undoButton.setEnabled(canUndo);
            redoButton.setEnabled(canRedo);

            undoButton.setToolTipText(canUndo ? m.getUndoPresentationName() : null);
            redoButton.setToolTipText(canRedo ? m.getRedoPresentationName() : null);
        }
    });
}

From source file:hr.fer.zemris.vhdllab.view.TabbedEditorsView.java

@Override
protected JComponent createControl() {
    CommandManager commandManager = getActiveWindow().getCommandManager();
    CommandGroup commandGroup = commandManager.createCommandGroup("editorsMenu", new Object[] { "saveCommand",
            "saveAllCommand", "separator", "closeCommand", "closeOtherCommand", "closeAllCommand" });

    tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
    tabbedPane.setComponentPopupMenu(commandGroup.createPopupMenu());
    tabbedPane.addChangeListener(new ChangeListener() {
        @Override/* ww w  .ja  v  a2s.c o m*/
        public void stateChanged(ChangeEvent e) {
            if (!addingTab) {
                int index = tabbedPane.getSelectedIndex();
                container.setSelected(index);
            }
        }
    });
    return tabbedPane;
}

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

private void initGUI() {
    try {/*from  ww  w .  j ava2 s .c  o  m*/
        DocumentListener docListener = JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
            public void process(DocumentEvent event) {
                jText1OrJArea1Change(event);
            }
        });

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        {
            jTabbedPane1 = new JTabbedPane();
            jTabbedPane1.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    jText1OrJArea1Change(null);
                }
            });
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("src text", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        srcArea = new JTextArea();
                        jScrollPane1.setViewportView(srcArea);
                        srcArea.setBorder(
                                BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0)));
                        JCommonUtil.setFont(srcArea);
                        srcArea.addKeyListener(new KeyAdapter() {
                            @Override
                            public void keyPressed(KeyEvent e) {
                                jText1OrJArea1Change(null);
                            }
                        });
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("group", null, jPanel2, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(398, 234));
                    {
                        ListModel groupListModel = new DefaultComboBoxModel();
                        groupList = new JList();
                        jScrollPane2.setViewportView(groupList);
                        groupList.setBorder(
                                BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0)));
                        groupList.setModel(groupListModel);
                        JCommonUtil.setFont(groupList);
                    }
                }
                {
                    regexText0 = new JTextField();
                    jPanel2.add(regexText0, BorderLayout.NORTH);
                    regexText0.setBorder(
                            BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0)));
                    JCommonUtil.setFont(regexText0);
                    regexText0.getDocument().addDocumentListener(docListener);
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("scanner", null, jPanel3, null);
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel3.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        ListModel scannerListModel = new DefaultComboBoxModel();
                        scannerList = new JList();
                        jScrollPane3.setViewportView(scannerList);
                        scannerList.setBorder(
                                BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0)));
                        scannerList.setModel(scannerListModel);
                        JCommonUtil.setFont(scannerList);
                    }
                }
                {
                    regexText = new JTextField();
                    jPanel3.add(regexText, BorderLayout.NORTH);
                    regexText.setBorder(
                            BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 0)));
                    JCommonUtil.setFont(regexText);
                    regexText.getDocument().addDocumentListener(docListener);
                }
            }
        }
        this.setTitle("\u6b63\u5247\u8868\u793a\u5f0f");
        this.setSize(419, 320);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.sshtools.common.ui.SshToolsConnectionProxyTab.java

/**
 * Creates a new SshToolsConnectionProxyTab object.
 *///from   www. j  a v a2s.c  o m
public SshToolsConnectionProxyTab() {
    super();
    group.add(noProxy);
    group.add(httpProxy);
    group.add(socks4Proxy);
    group.add(socks5Proxy);

    ChangeListener listener = new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            if (noProxy.isSelected()) {
                username.setEnabled(false);
                password.setEnabled(false);
                proxy.setEnabled(false);

                //port.setEnabled(false);
                port.setForeground(Color.white);
            } else {
                username.setEnabled(true);
                password.setEnabled(true);
                proxy.setEnabled(true);

                //port.setEnabled(true);
                port.setForeground(Color.black);

                if (httpProxy.isSelected()) {
                    port.setText("80");
                } else {
                    port.setText("1080");
                }
            }
        }
    };

    noProxy.getModel().addChangeListener(listener);
    httpProxy.getModel().addChangeListener(listener);
    socks4Proxy.getModel().addChangeListener(listener);
    socks5Proxy.getModel().addChangeListener(listener);

    //  Create the main connection details panel
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.insets = new Insets(0, 2, 2, 2);
    gbc.weightx = 1.0;
    proxyframe.setBorder(BorderFactory.createTitledBorder("Connect using the following proxy"));

    //  No proxy label
    gbc.insets = new Insets(2, 10, 2, 2);
    UIUtil.jGridBagAdd(proxyframe, noProxy, gbc, GridBagConstraints.RELATIVE);

    // Socks 4 label
    gbc.insets = new Insets(2, 15, 2, 2);
    UIUtil.jGridBagAdd(proxyframe, socks4Proxy, gbc, GridBagConstraints.REMAINDER);

    //gbc.fill = GridBagConstraints.HORIZONTAL;
    // Http Proxy
    gbc.insets = new Insets(2, 10, 2, 2);
    UIUtil.jGridBagAdd(proxyframe, httpProxy, gbc, GridBagConstraints.RELATIVE);

    // Socks 5 label
    gbc.insets = new Insets(2, 15, 2, 2);
    UIUtil.jGridBagAdd(proxyframe, socks5Proxy, gbc, GridBagConstraints.REMAINDER);

    gbc.insets = new Insets(2, 10, 2, 10);

    JPanel connect = new JPanel(new GridBagLayout());
    connect.setBorder(BorderFactory.createTitledBorder("Proxy Details"));
    UIUtil.jGridBagAdd(connect, new JLabel("Host"), gbc, GridBagConstraints.REMAINDER);

    UIUtil.jGridBagAdd(connect, proxy, gbc, GridBagConstraints.REMAINDER);

    UIUtil.jGridBagAdd(connect, new JLabel("Port"), gbc, GridBagConstraints.REMAINDER);
    gbc.anchor = GridBagConstraints.WEST;
    gbc.fill = GridBagConstraints.NONE;

    UIUtil.jGridBagAdd(connect, port, gbc, GridBagConstraints.REMAINDER);
    gbc.fill = GridBagConstraints.HORIZONTAL;

    UIUtil.jGridBagAdd(connect, new JLabel("Username"), gbc, GridBagConstraints.REMAINDER);

    UIUtil.jGridBagAdd(connect, username, gbc, GridBagConstraints.REMAINDER);

    UIUtil.jGridBagAdd(connect, new JLabel("Password"), gbc, GridBagConstraints.REMAINDER);
    gbc.insets = new Insets(2, 10, 10, 10);
    UIUtil.jGridBagAdd(connect, password, gbc, GridBagConstraints.REMAINDER);

    JPanel main = new JPanel(new GridBagLayout());
    gbc.insets = new Insets(2, 2, 2, 2);
    UIUtil.jGridBagAdd(main, proxyframe, gbc, GridBagConstraints.REMAINDER);
    UIUtil.jGridBagAdd(main, connect, gbc, GridBagConstraints.REMAINDER);

    IconWrapperPanel iconProxyDetailsPanel = new IconWrapperPanel(new ResourceIcon(PROXY_ICON), main);
    noProxy.setSelected(true);

    //  This panel
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.weightx = 1.0;
    add(iconProxyDetailsPanel, BorderLayout.NORTH);
}

From source file:CompositeTest.java

public CompositeTestFrame() {
    setTitle("CompositeTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    canvas = new CompositeComponent();
    add(canvas, BorderLayout.CENTER);

    ruleCombo = new JComboBox(new Object[] { new Rule("CLEAR", "  ", "  "), new Rule("SRC", " S", " S"),
            new Rule("DST", "  ", "DD"), new Rule("SRC_OVER", " S", "DS"), new Rule("DST_OVER", " S", "DD"),
            new Rule("SRC_IN", "  ", " S"), new Rule("SRC_OUT", " S", "  "), new Rule("DST_IN", "  ", " D"),
            new Rule("DST_OUT", "  ", "D "), new Rule("SRC_ATOP", "  ", "DS"), new Rule("DST_ATOP", " S", " D"),
            new Rule("XOR", " S", "D "), });
    ruleCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Rule r = (Rule) ruleCombo.getSelectedItem();
            canvas.setRule(r.getValue());
            explanation.setText(r.getExplanation());
        }//from  w  ww .j  a v a2  s.c  om
    });

    alphaSlider = new JSlider(0, 100, 75);
    alphaSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            canvas.setAlpha(alphaSlider.getValue());
        }
    });
    JPanel panel = new JPanel();
    panel.add(ruleCombo);
    panel.add(new JLabel("Alpha"));
    panel.add(alphaSlider);
    add(panel, BorderLayout.NORTH);

    explanation = new JTextField();
    add(explanation, BorderLayout.SOUTH);

    canvas.setAlpha(alphaSlider.getValue());
    Rule r = (Rule) ruleCombo.getSelectedItem();
    canvas.setRule(r.getValue());
    explanation.setText(r.getExplanation());
}

From source file:nl.umcg.qube.ui.StatisticsPanel.java

public StatisticsPanel(CAGPanel cag_panel) {
    super(new BorderLayout());
    cagPanel = cag_panel;// w  w w  .java  2s  .c o m
    cagPanel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent arg0) {
            // redrawing the chart during sequence viewing is very slow
            // don't update it therefore.
            if (chart != null && !cagPanel.sequenceRunning()) {
                chart.getXYPlot().clearDomainMarkers();
                chart.getXYPlot().addDomainMarker(new ValueMarker(cagPanel.getCurrentFrameNo() + 1));
            }
        }
    });

    JPanel commandPanel = new JPanel();

    JButton calc = new JButton("Recalculate");
    calc.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            recalc();
        }
    });
    commandPanel.add(calc);

    blushLabel = new JLabel("");
    commandPanel.add(blushLabel);

    add(commandPanel, BorderLayout.NORTH);

    dataSet = new DefaultXYDataset();
    chart = ChartFactory.createXYLineChart("Blush value", "Frame no.", "arbitrary units", dataSet,
            PlotOrientation.VERTICAL, true, false, false);
    chartPanel = new ChartPanel(chart);
    add(chartPanel);
}

From source file:MainClass.java

public MainClass() {
    Container cp = new Box(BoxLayout.X_AXIS);
    setContentPane(cp);// w w  w .  j a  v a  2s  . co m
    JPanel firstPanel = new JPanel();
    propertyComboBox = new JComboBox();
    propertyComboBox.addItem("text");
    propertyComboBox.addItem("font");
    propertyComboBox.addItem("background");
    propertyComboBox.addItem("foreground");
    firstPanel.add(propertyComboBox);
    cp.add(firstPanel);
    cp.add(Box.createGlue());

    tf = new JTextField("Hello");
    tf.setForeground(Color.RED);
    tf.setDragEnabled(true);
    cp.add(tf);

    cp.add(Box.createGlue());

    l = new JLabel("Hello");
    l.setBackground(Color.YELLOW);
    cp.add(l);

    cp.add(Box.createGlue());

    JSlider stryder = new JSlider(SwingConstants.VERTICAL);
    stryder.setMinimum(10);
    stryder.setValue(14);
    stryder.setMaximum(72);
    stryder.setMajorTickSpacing(10);
    stryder.setPaintTicks(true);

    cp.add(stryder);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(500, 300);

    setMyTransferHandlers((String) propertyComboBox.getSelectedItem());

    MouseListener myDragListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            handler.exportAsDrag(c, e, TransferHandler.COPY);
        }
    };
    l.addMouseListener(myDragListener);

    propertyComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ce) {
            JComboBox bx = (JComboBox) ce.getSource();
            String prop = (String) bx.getSelectedItem();
            setMyTransferHandlers(prop);
        }
    });

    tf.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JTextField jtf = (JTextField) evt.getSource();
            String fontName = jtf.getText();
            Font font = new Font(fontName, Font.BOLD, 18);
            tf.setFont(font);
        }
    });

    stryder.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            JSlider sl = (JSlider) evt.getSource();
            Font oldf = tf.getFont();
            Font newf = oldf.deriveFont((float) sl.getValue());
            tf.setFont(newf);
        }
    });
}

From source file:TabbedPaneTest.java

public TabbedPaneFrame() {
    setTitle("TabbedPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    tabbedPane = new JTabbedPane();
    // we set the components to null and delay their loading until the tab is shown
    // for the first time

    ImageIcon icon = new ImageIcon("yellow-ball.gif");

    tabbedPane.addTab("Mercury", icon, null);
    tabbedPane.addTab("Venus", icon, null);
    tabbedPane.addTab("Earth", icon, null);
    tabbedPane.addTab("Mars", icon, null);
    tabbedPane.addTab("Jupiter", icon, null);
    tabbedPane.addTab("Saturn", icon, null);
    tabbedPane.addTab("Uranus", icon, null);
    tabbedPane.addTab("Neptune", icon, null);
    tabbedPane.addTab("Pluto", null, null);

    final int plutoIndex = tabbedPane.indexOfTab("Pluto");
    JPanel plutoPanel = new JPanel();
    plutoPanel.add(new JLabel("Pluto", icon, SwingConstants.LEADING));
    JToggleButton plutoCheckBox = new JCheckBox();
    plutoCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tabbedPane.remove(plutoIndex);
        }/*www.  j  ava  2s  .co  m*/
    });
    plutoPanel.add(plutoCheckBox);
    tabbedPane.setTabComponentAt(plutoIndex, plutoPanel);

    add(tabbedPane, "Center");

    tabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {

            // check if this tab still has a null component

            if (tabbedPane.getSelectedComponent() == null) {
                // set the component to the image icon

                int n = tabbedPane.getSelectedIndex();
                loadTab(n);
            }
        }
    });

    loadTab(0);

    JPanel buttonPanel = new JPanel();
    ButtonGroup buttonGroup = new ButtonGroup();
    JRadioButton wrapButton = new JRadioButton("Wrap tabs");
    wrapButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
        }
    });
    buttonPanel.add(wrapButton);
    buttonGroup.add(wrapButton);
    wrapButton.setSelected(true);
    JRadioButton scrollButton = new JRadioButton("Scroll tabs");
    scrollButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        }
    });
    buttonPanel.add(scrollButton);
    buttonGroup.add(scrollButton);
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:House.java

public JSlider setSlider(JPanel panel, int orientation, int minimumValue, int maximumValue, int initValue,
        int majorTickSpacing, int minorTickSpacing) {
    JSlider slider = new JSlider(orientation, minimumValue, maximumValue, initValue);
    slider.setPaintTicks(true);//from w ww  .j a  v  a  2s  .c o  m
    slider.setMajorTickSpacing(majorTickSpacing);
    slider.setMinorTickSpacing(minorTickSpacing);
    slider.setPaintLabels(true);
    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider tempSlider = (JSlider) e.getSource();

            if (tempSlider.equals(sliderTransX)) {
                transX = sliderTransX.getValue() - 150.0;
                canvas.repaint();
            } else if (tempSlider.equals(sliderTransY)) {
                transY = sliderTransY.getValue() - 150.0;
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateTheta)) {
                rotateTheta = sliderRotateTheta.getValue() * Math.PI / 180;
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateX)) {
                rotateX = sliderRotateX.getValue();
                canvas.repaint();
            } else if (tempSlider.equals(sliderRotateY)) {
                rotateY = sliderRotateY.getValue();
                canvas.repaint();
            } else if (tempSlider.equals(sliderScaleX)) {
                if (sliderScaleX.getValue() != 0.0) {
                    scaleX = sliderScaleX.getValue() / 100.0;
                    canvas.repaint();
                }
            } else if (tempSlider.equals(sliderScaleY)) {
                if (sliderScaleY.getValue() != 0.0) {
                    scaleY = sliderScaleY.getValue() / 100.0;
                    canvas.repaint();
                }
            }
        }
    });
    panel.add(slider);

    return slider;
}

From source file:net.lldp.checksims.ui.results.ScrollViewer.java

/**
 * Create a scroll viewer from a sortable Matrix Viewer
 * @param results the sortableMatrix to view
 * @param toRevalidate frame to revalidate sometimes
 *//* w  w  w  . jav a 2s  . c o  m*/
public ScrollViewer(SimilarityMatrix exportMatrix, SortableMatrixViewer results, JFrame toRevalidate) {
    resultsView = new JScrollPane(results);
    setBackground(Color.black);
    resultsView.addComponentListener(new ComponentListener() {

        @Override
        public void componentHidden(ComponentEvent arg0) {
        }

        @Override
        public void componentMoved(ComponentEvent arg0) {
        }

        @Override
        public void componentResized(ComponentEvent ce) {
            Dimension size = ce.getComponent().getSize();
            results.padToSize(size);
        }

        @Override
        public void componentShown(ComponentEvent arg0) {
        }
    });

    resultsView.getViewport().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            Rectangle r = resultsView.getViewport().getViewRect();
            results.setViewAt(r);
        }
    });

    resultsView.setBackground(Color.black);
    sidebar = new JPanel();

    setPreferredSize(new Dimension(900, 631));
    setMinimumSize(new Dimension(900, 631));
    sidebar.setPreferredSize(new Dimension(200, 631));
    sidebar.setMaximumSize(new Dimension(200, 3000));
    resultsView.setMinimumSize(new Dimension(700, 631));
    resultsView.setPreferredSize(new Dimension(700, 631));

    sidebar.setBackground(Color.GRAY);

    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    this.add(sidebar);
    this.add(resultsView);

    resultsView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    resultsView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    resultsView.getVerticalScrollBar().setUnitIncrement(16);
    resultsView.getHorizontalScrollBar().setUnitIncrement(16);

    Integer[] presetThresholds = { 80, 60, 40, 20, 0 };
    JComboBox<Integer> threshHold = new JComboBox<Integer>(presetThresholds);
    threshHold.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Integer item = (Integer) event.getItem();
                results.updateThreshold(item / 100.0);
                toRevalidate.revalidate();
                toRevalidate.repaint();
            }
        }
    });
    threshHold.setSelectedIndex(0);
    results.updateThreshold((Integer) threshHold.getSelectedItem() / 100.0);

    JTextField student1 = new JTextField(15);
    JTextField student2 = new JTextField(15);

    KeyListener search = new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            results.highlightMatching(student1.getText(), student2.getText());
            toRevalidate.revalidate();
            toRevalidate.repaint();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }
    };

    student1.addKeyListener(search);
    student2.addKeyListener(search);

    Collection<MatrixPrinter> printerNameSet = MatrixPrinterRegistry.getInstance()
            .getSupportedImplementations();
    JComboBox<MatrixPrinter> exportAs = new JComboBox<>(new Vector<>(printerNameSet));
    JButton exportAsSave = new JButton("Save");

    JFileChooser fc = new JFileChooser();

    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setCurrentDirectory(new java.io.File("."));
    fc.setDialogTitle("Save results");

    exportAsSave.addActionListener(ae -> {
        MatrixPrinter method = (MatrixPrinter) exportAs.getSelectedItem();

        int err = fc.showDialog(toRevalidate, "Save");
        if (err == JFileChooser.APPROVE_OPTION) {
            try {
                FileUtils.writeStringToFile(fc.getSelectedFile(), method.printMatrix(exportMatrix));
            } catch (InternalAlgorithmError | IOException e1) {
                // TODO log / show error
            }
        }
    });

    JPanel thresholdLabel = new JPanel();
    JPanel studentSearchLabel = new JPanel();
    JPanel fileOutputLabel = new JPanel();

    thresholdLabel.setBorder(BorderFactory.createTitledBorder("Matching Threshold"));
    studentSearchLabel.setBorder(BorderFactory.createTitledBorder("Student Search"));
    fileOutputLabel.setBorder(BorderFactory.createTitledBorder("Save Results"));

    thresholdLabel.add(threshHold);
    studentSearchLabel.add(student1);
    studentSearchLabel.add(student2);
    fileOutputLabel.add(exportAs);
    fileOutputLabel.add(exportAsSave);

    studentSearchLabel.setPreferredSize(new Dimension(200, 100));
    studentSearchLabel.setMinimumSize(new Dimension(200, 100));
    thresholdLabel.setPreferredSize(new Dimension(200, 100));
    thresholdLabel.setMinimumSize(new Dimension(200, 100));
    fileOutputLabel.setPreferredSize(new Dimension(200, 100));
    fileOutputLabel.setMinimumSize(new Dimension(200, 100));

    sidebar.setMaximumSize(new Dimension(200, 4000));

    sidebar.add(thresholdLabel);
    sidebar.add(studentSearchLabel);
    sidebar.add(fileOutputLabel);
}