Example usage for javax.swing JScrollBar getMaximum

List of usage examples for javax.swing JScrollBar getMaximum

Introduction

In this page you can find the example usage for javax.swing JScrollBar getMaximum.

Prototype

public int getMaximum() 

Source Link

Document

The maximum value of the scrollbar is maximum - extent.

Usage

From source file:Main.java

/**
 * Move the cursor to the end of ScrollPane.
 *
 * @param pane the ScrollPane//from   w  w w. j  a  v  a 2  s .  c  om
 */
public static void moveEnd(JScrollPane pane) {
    JScrollBar bar = pane.getVerticalScrollBar();
    bar.setValue(bar.getMaximum());
}

From source file:Main.java

/**
 * Scrolls the given component to its top or bottom.
 * Useful for implementing behavior like in Apple's Mail where home/end in the list cause scrolling in the text.
 *///from   w  ww  . jav a2 s . c  o m
public static void scrollToExtremity(JComponent c, boolean top) {
    JScrollBar scrollBar = ((JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, c))
            .getVerticalScrollBar();
    scrollBar.setValue(top ? scrollBar.getMinimum() : scrollBar.getMaximum());
}

From source file:Main.java

/**
 * Scrolls the given component by its unit or block increment in the given direction (actually a scale factor, so use +1 or -1).
 * Useful for implementing behavior like in Apple's Mail where page up/page down in the list cause scrolling in the text.
 *//*from   w  w w.j a v a2s .  c  om*/
public static void scroll(JComponent c, boolean byBlock, int direction) {
    JScrollPane scrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, c);
    JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
    int increment = byBlock ? scrollBar.getBlockIncrement(direction) : scrollBar.getUnitIncrement(direction);
    int newValue = scrollBar.getValue() + direction * increment;
    newValue = Math.min(newValue, scrollBar.getMaximum());
    newValue = Math.max(newValue, scrollBar.getMinimum());
    scrollBar.setValue(newValue);
}

From source file:Main.java

public static void scrollByBlock(JScrollBar scrollbar, int direction) {
    // This method is called from BasicScrollPaneUI to implement wheel
    // scrolling, and also from scrollByBlock().
    int oldValue = scrollbar.getValue();
    int blockIncrement = scrollbar.getBlockIncrement(direction);
    int delta = blockIncrement * ((direction > 0) ? +1 : -1);
    int newValue = oldValue + delta;

    // Check for overflow.
    if (delta > 0 && newValue < oldValue) {
        newValue = scrollbar.getMaximum();
    } else if (delta < 0 && newValue > oldValue) {
        newValue = scrollbar.getMinimum();
    }//w w w . j av  a  2s .  c o m

    scrollbar.setValue(newValue);
}

From source file:ca.uhn.hl7v2.testpanel.ui.ActivityDetailsCellRenderer.java

@Override
public Component getTableCellRendererComponent(final JTable theTable, Object theValue, boolean theIsSelected,
        boolean theHasFocus, final int theRow, int theColumn) {
    super.getTableCellRendererComponent(theTable, theValue, theIsSelected, theHasFocus, theRow, theColumn);

    if (theValue instanceof ActivityInfo) {

        renderInfo(theTable, theValue, theRow);

    } else if (theValue instanceof ActivityMessage) {

        renderMessage(theTable, theValue, theRow, theIsSelected);

    } else if (theValue instanceof ActivityBytesBase) {

        renderBytes(theTable, theValue, theRow);

    } else if (theValue instanceof ActivityValidationOutcome) {

        renderValidation(theTable, (ActivityValidationOutcome) theValue, theRow);

    }// ww  w  .j  a  v a 2 s.  co  m

    // int prefHeight = getPreferredSize().height;
    // prefHeight = Math.max(prefHeight, 10);
    // if (prefHeight != theTable.getRowHeight(theRow)) {
    // ourLog.trace("Setting height of row {} to {}", theRow, prefHeight);
    // theTable.setRowHeight(theRow, prefHeight);
    // }

    // EventQueue.invokeLater(new Runnable() {
    // public void run() {
    // int minWidth = getPreferredSize().width + 200;
    //
    // if (minWidth > theTable.getColumnModel().getColumn(2).getWidth()) {
    // theTable.getColumnModel().getColumn(2).setMinWidth(getPreferredSize().width);
    // theTable.getColumnModel().getColumn(2).setMaxWidth(getPreferredSize().width);
    // theTable.getColumnModel().getColumn(2).setPreferredWidth(getPreferredSize().width);
    // }
    // }});

    // ourLog.info("Rendering row {}", theRow);

    // EventQueue.invokeLater(new Runnable() {
    // public void run() {
    // getTablePanel().
    // JScrollBar vsb = myscrollPane.getVerticalScrollBar();
    // vsb.setValue(vsb.getMaximum());
    // ourLog.info("Setting scrollbar to bottom: {}", vsb.getMaximum());
    // }
    // });
    if (myScrollToBottom) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JScrollBar vsb = getTablePanel().getScrollPane().getVerticalScrollBar();
                int newValue = vsb.getMaximum();
                int existingValue = vsb.getValue();
                if (newValue != existingValue) {
                    vsb.setValue(newValue);
                    ourLog.debug("Setting scrollbar to bottom, from {} to {}", existingValue, newValue);
                }

                if (theRow == getTablePanel().getTableModel().getRowCount() - 1) {
                    myScrollToBottom = false;
                }
            }
        });

    }

    return this;
}

From source file:me.mayo.telnetkek.MainPanel.java

private void writeToConsoleImmediately(final ConsoleMessage message, final boolean isTelnetError) {
    SwingUtilities.invokeLater(() -> {
        if (isTelnetError && chkIgnoreErrors.isSelected()) {
            return;
        }//from  w w  w  .ja  va  2s  .  c  om

        final StyledDocument styledDocument = mainOutput.getStyledDocument();

        int startLength = styledDocument.getLength();

        try {
            styledDocument.insertString(styledDocument.getLength(),
                    message.getMessage() + System.lineSeparator(),
                    StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY,
                            StyleConstants.Foreground, message.getColor()));
        } catch (BadLocationException ex) {
            throw new RuntimeException(ex);
        }

        if (MainPanel.this.chkAutoScroll.isSelected() && MainPanel.this.mainOutput.getSelectedText() == null) {
            final JScrollBar vScroll = mainOutputScoll.getVerticalScrollBar();

            if (!vScroll.getValueIsAdjusting()) {
                if (vScroll.getValue() + vScroll.getModel().getExtent() >= (vScroll.getMaximum() - 50)) {
                    MainPanel.this.mainOutput.setCaretPosition(startLength);

                    final Timer timer = new Timer(10, (ActionEvent ae) -> {
                        vScroll.setValue(vScroll.getMaximum());
                    });
                    timer.setRepeats(false);
                    timer.start();
                }
            }
        }
    });
}

From source file:Display.java

@SuppressWarnings("unchecked")
Display() {/*from w  ww.j ava  2s .  c  om*/
    super(Reference.NAME);
    cardLayout = new CardLayout();
    panel.setLayout(cardLayout);
    final int java7Update = Utils.Validators.java7Update.check();
    final int java8Update = Utils.Validators.java8Update.check();
    try {
        URL host = new URL(Reference.PROTOCOL, Reference.SOURCE_HOST, Reference.PORT, Reference.JSON_ARRAY);
        JSONParser parser = new JSONParser();
        Object json = parser.parse(new URLReader(host));
        final JSONArray array = (JSONArray) json;
        JSONObject nameObject1 = (JSONObject) array.get(0);
        XPackInstaller.selected_url = nameObject1.get("url").toString();
        XPackInstaller.javaVersion = Integer.parseInt(nameObject1.get("version").toString());
        XPackInstaller.profile = nameObject1.get("profile").toString();
        XPackInstaller.canAcceptOptional = Boolean
                .parseBoolean(nameObject1.get("canAcceptOptional").toString());
        if (!XPackInstaller.canAcceptOptional) {
            checkOptifine.setEnabled(false);
            checkOptifine.setSelected(false);
            zainstalujMoCreaturesCheckBox.setEnabled(false);
            zainstalujMoCreaturesCheckBox.setSelected(false);
            optionalText.setEnabled(false);
        } else {
            checkOptifine.setEnabled(true);
            zainstalujMoCreaturesCheckBox.setEnabled(true);
            optionalText.setEnabled(true);
        }
        for (Object anArray : array) {
            comboBox1.addItem(new JSONObject((JSONObject) anArray).get("name"));
        }
        comboBox1.addActionListener(e -> {
            int i = 0;
            while (true) {
                JSONObject nameObject = (JSONObject) array.get(i);
                String name1 = nameObject.get("name").toString();
                if (name1 == comboBox1.getSelectedItem()) {
                    XPackInstaller.canAcceptOptional = Boolean
                            .parseBoolean(nameObject.get("canAcceptOptional").toString());
                    XPackInstaller.selected_url = nameObject.get("url").toString();
                    XPackInstaller.javaVersion = Integer.parseInt(nameObject.get("version").toString());
                    XPackInstaller.profile = nameObject.get("profile").toString();
                    if (!XPackInstaller.canAcceptOptional) {
                        checkOptifine.setEnabled(false);
                        checkOptifine.setSelected(false);
                        zainstalujMoCreaturesCheckBox.setEnabled(false);
                        zainstalujMoCreaturesCheckBox.setSelected(false);
                        optionalText.setEnabled(false);
                    } else {
                        checkOptifine.setEnabled(true);
                        zainstalujMoCreaturesCheckBox.setEnabled(true);
                        optionalText.setEnabled(true);
                    }
                    break;
                }
                i++;
            }
            int javaStatus;
            if (XPackInstaller.javaVersion == 8) {
                javaStatus = java8Update;
            } else {
                javaStatus = java7Update;
            }
            if (javaStatus == 0) {
                javaversion.setText("TAK");
                javaversion.setForeground(Reference.COLOR_DARK_GREEN);
            } else if (javaStatus == 1) {
                javaversion.setText("NIE");
                javaversion.setForeground(Reference.COLOR_DARK_ORANGE);
            } else if (javaStatus == 2) {
                if (XPackInstaller.javaVersion == 8) {
                    javaversion.setText("Nie posiadasz JRE8 w wersji 25 lub nowszej!");
                } else {
                    javaversion.setText("Nie posiadasz najnowszej wersji JRE7!");
                }
                javaversion.setForeground(Color.RED);
            }
            if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK")
                    && javaarch.getText().equals("TAK")
                    && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) {
                XPackInstaller.canGoForward = true;
                button2.setText("Dalej");
            } else {
                XPackInstaller.canGoForward = false;
                button2.setText("Anuluj");
            }
        });
    } catch (FileNotFoundException | ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd",
                JOptionPane.ERROR_MESSAGE);
        System.exit(0);
    }

    pobierzOryginalnyLauncherMCCheckBox.addActionListener(e -> {
        if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) {
            PathLauncherLabel.setEnabled(true);
            textField1.setEnabled(true);
            button3.setEnabled(true);
            XPackInstaller.installLauncher = true;
            labelLauncher.setEnabled(true);
            progressBar3.setEnabled(true);
        } else {
            PathLauncherLabel.setEnabled(false);
            textField1.setEnabled(false);
            button3.setEnabled(false);
            XPackInstaller.installLauncher = false;
            labelLauncher.setEnabled(false);
            progressBar3.setEnabled(false);
        }
    });
    button3.addActionListener(e -> {
        JFileChooser chooser = new JFileChooser(System.getProperty("user.home"));
        chooser.setApproveButtonText("Wybierz");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogTitle("Wybierz ciek");
        int returnValue = chooser.showOpenDialog(getContentPane());
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            try {
                XPackInstaller.launcher_path = chooser.getSelectedFile().getCanonicalPath();
            } catch (IOException x) {
                x.printStackTrace();
            }
            textField1.setText(XPackInstaller.launcher_path);
        }
    });
    slider1.setMaximum(Utils.Utils.humanReadableRAM() - 2);
    slider1.addChangeListener(e -> XPackInstaller.allocatedRAM = slider1.getValue());
    button1.addActionListener(e -> {
        if (pobierzOryginalnyLauncherMCCheckBox.isSelected()) {
            File launcher = new File(XPackInstaller.launcher_path + File.separator + "Minecraft.exe");
            if (textField1.getText().equals("")) {
                JOptionPane.showMessageDialog(panel, "Nie wybrae cieki instalacji Launcher'a!",
                        "Bd", JOptionPane.ERROR_MESSAGE);
            } else if (launcher.exists()) {
                JOptionPane.showMessageDialog(panel,
                        "W podanym katalogu istanieje ju plik o nazwie 'Minecraft.exe'!", "Bad",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                cardLayout.next(panel);
            }
        } else {
            cardLayout.next(panel);
            if (osarch.getText().equals("NIE") && Ram.getText().equals("TAK")
                    && javaarch.getText().equals("NIE")
                    && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) {
                XPackInstaller.canGoForward = false;
                button2.setText("Anuluj");
                JOptionPane.showMessageDialog(gui,
                        "Prosimy sprawdzi\u0107 czy na komputerze nie ma zainstalowanych dw\u00f3ch \u015brodowisk Java: w wersji 32-bitowej i 64-bitowej.\nJe\u015bli zainstalowane s\u0105 obie wersje prosimy o odinstalowanie wersji 32-bitowej. To rozwi\u0105\u017ce problem.",
                        "B\u0142\u0105d konfiguracji Javy", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    if (Utils.Validators.systemArchitecture.check()) {
        osarch.setText("TAK");
        osarch.setForeground(Reference.COLOR_DARK_GREEN);
    } else {
        osarch.setText("NIE");
        osarch.setForeground(Color.RED);
    }
    if (Utils.Validators.ramAmount.check()) {
        Ram.setText("TAK");
        Ram.setForeground(Reference.COLOR_DARK_GREEN);
    } else {
        Ram.setText("NIE");
        Ram.setForeground(Color.RED);
    }
    if (Utils.Validators.javaArchitecture.check()) {
        javaarch.setText("TAK");
        javaarch.setForeground(Reference.COLOR_DARK_GREEN);
    } else {
        javaarch.setText("NIE");
        javaarch.setForeground(Color.RED);
    }
    int javaStatus;

    if (XPackInstaller.javaVersion == 8) {
        javaStatus = java8Update;
    } else {
        javaStatus = java7Update;
    }

    if (javaStatus == 0) {
        javaversion.setText("TAK");
        javaversion.setForeground(Reference.COLOR_DARK_GREEN);
    } else if (javaStatus == 1) {
        javaversion.setText("NIE");
        javaversion.setForeground(Reference.COLOR_DARK_ORANGE);
    } else if (javaStatus == 2) {
        javaversion.setText("Nie posiadasz najnowszej wersji JRE!");
        javaversion.setForeground(Color.RED);
    }
    if (osarch.getText().equals("TAK") && Ram.getText().equals("TAK") && javaarch.getText().equals("TAK")
            && (javaversion.getText().equals("TAK") || javaversion.getText().equals("NIE"))) {
        XPackInstaller.canGoForward = true;
        button2.setText("Dalej");
    } else {
        XPackInstaller.canGoForward = false;
        button2.setText("Anuluj");
    }
    button2.addActionListener(e -> {
        if (XPackInstaller.canGoForward) {
            cardLayout.next(panel);
        } else {
            System.exit(1);
        }
    });
    wsteczButton.addActionListener(e -> cardLayout.previous(panel));
    try {
        editorPane1.setPage("http://xpack.pl/licencja.html");
    } catch (IOException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(panel, "Brak poczenia z Internetem!", "Bd",
                JOptionPane.ERROR_MESSAGE);
        System.exit(0);
    }
    licenseC.addActionListener(e -> {
        if (licenseC.isSelected()) {
            dalejButton.setEnabled(true);
        } else {
            dalejButton.setEnabled(false);
        }
    });
    try {
        File mainDir = new File(System.getenv("appdata") + File.separator + "XPackInstaller");
        if (mainDir.exists()) {
            FileUtils.deleteDirectory(mainDir);
            if (!mainDir.mkdir()) {
                JOptionPane.showMessageDialog(gui,
                        "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd",
                        JOptionPane.ERROR_MESSAGE);
                System.out.println("Nie udao si utworzy katalogu!");
                System.exit(1);
            }
        } else {
            if (!mainDir.mkdir()) {
                JOptionPane.showMessageDialog(gui,
                        "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd",
                        JOptionPane.ERROR_MESSAGE);
                System.out.println("Nie udao si utworzy katalogu!");
                System.exit(1);
            }
        }
        File optionalDir = new File(mainDir.getAbsolutePath() + File.separator + "OptionalMods");
        if (!optionalDir.mkdir()) {
            JOptionPane.showMessageDialog(gui,
                    "Nie udao si utworzy katalogu, prosimy sprbowa ponownie!", "Bd",
                    JOptionPane.ERROR_MESSAGE);
            System.out.println("Nie udao si utworzy katalogu!");
            System.exit(1);
        }
        dalejButton.addActionListener(e -> {
            cardLayout.next(panel);
            try {
                progressBar1.setValue(0);
                if (checkOptifine.isSelected() && zainstalujMoCreaturesCheckBox.isSelected()) {
                    DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine,
                            optionalDir.getAbsolutePath());
                    task2.addPropertyChangeListener(evt -> {
                        if (evt.getPropertyName().equals("progress")) {
                            labelmodpack.setText("Pobieranie Optifine HD w toku...");
                            if (task2.isDone()) {
                                task3();
                            }
                            optifineProgress = (Integer) evt.getNewValue();
                            progressBar1.setValue(optifineProgress);
                        }
                    });
                    task2.execute();
                } else if (checkOptifine.isSelected()) {
                    DownloadTask task2 = new DownloadTask(gui, "mod", Reference.downloadOptifine,
                            optionalDir.getAbsolutePath());
                    task2.addPropertyChangeListener(evt -> {
                        if (evt.getPropertyName().equals("progress")) {
                            labelmodpack.setText("Pobieranie Optifine HD w toku...");
                            if (task2.isDone()) {
                                task();
                            }
                            optifineProgress = (Integer) evt.getNewValue();
                            progressBar1.setValue(optifineProgress);
                        }
                    });
                    task2.execute();
                } else if (zainstalujMoCreaturesCheckBox.isSelected()) {
                    task3();
                } else {
                    task();
                }
            } catch (Exception exx) {
                exx.printStackTrace();
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }

    final JScrollBar bar = scrollPane1.getVerticalScrollBar();
    bar.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int extent = bar.getModel().getExtent();
            int total = extent + bar.getValue();
            int max = bar.getMaximum();
            if (total == max) {
                licenseC.setEnabled(true);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            int extent = bar.getModel().getExtent();
            int total = extent + bar.getValue();
            int max = bar.getMaximum();
            if (total == max) {
                licenseC.setEnabled(true);
            }
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    bar.addMouseWheelListener(e -> {
        int extent = bar.getModel().getExtent();
        int total = extent + bar.getValue();
        int max = bar.getMaximum();
        if (total == max) {
            licenseC.setEnabled(true);
        }
    });
    scrollPane1.setWheelScrollingEnabled(true);
    scrollPane1.addMouseWheelListener(e -> {
        int extent = bar.getModel().getExtent();
        int total = extent + bar.getValue();
        int max = bar.getMaximum();
        if (total == max) {
            licenseC.setEnabled(true);
        }
    });
    panel.add(panel3);
    panel.add(panel1);
    panel.add(panel2);
    panel.add(panel4);
    add(panel);
}

From source file:GUI.GraphicalInterface.java

/**
 * Set scroll bar of {@code scrollPane} to extremum value.
 * <br> non-zero {@code value} means scroll to bottom.
 * <br> zero {@code value} means scroll to top.
 *
 * @param scrollPane {@code scrollPane} to be modified
 * @param value whether to scroll to top (zero) or bottom (non-zero)
 *///from www.j a  v a 2 s  .  c o  m
private void setScrollBar(final javax.swing.JScrollPane scrollPane, final int value) {
    /* set the position of scroll bar */
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (value == 0) {
                scrollPane.getVerticalScrollBar().setValue(0);
            } else {
                JScrollBar sb = scrollPane.getVerticalScrollBar();
                sb.setValue(sb.getMaximum());
            }
        }
    });
}

From source file:edu.purdue.cc.bionet.ui.GraphVisualizer.java

/**
 * Centers the graph in the display./*ww  w.j  a va2 s  .  c  om*/
 */
public void center() {
    // toggle the scrollbars back and forth to center the image
    JScrollBar sb = scrollPane.getHorizontalScrollBar();
    sb.setValue(sb.getMaximum());
    sb.setValue(sb.getMinimum());
    sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2);
    sb = scrollPane.getVerticalScrollBar();
    sb.setValue(sb.getMaximum());
    sb.setValue(sb.getMinimum());
    sb.setValue((sb.getMaximum() + sb.getMinimum()) / 2);
}

From source file:com.diversityarrays.dal.server.ServerGui.java

public ServerGui(Image serverIconImage, IDalServer svr, DalServerFactory factory, File wwwRoot,
        DalServerPreferences prefs) {/*from   www .  jav a  2  s. co  m*/

    this.serverIconImage = serverIconImage;
    this.dalServerFactory = factory;
    this.wwwRoot = wwwRoot;
    this.preferences = prefs;

    JMenuBar menuBar = new JMenuBar();

    JMenu serverMenu = new JMenu("Server");
    menuBar.add(serverMenu);
    serverMenu.add(serverStartAction);
    serverMenu.add(serverStopAction);
    serverMenu.add(exitAction);

    JMenu commandMenu = new JMenu("Command");
    menuBar.add(commandMenu);
    commandMenu.add(doSql);

    JMenu urlMenu = new JMenu("URL");
    menuBar.add(urlMenu);
    urlMenu.add(new JMenuItem(copyDalUrlAction));
    urlMenu.add(new JMenuItem(showDalUrlQRcodeAction));

    setJMenuBar(menuBar);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    messages.setFont(GuiUtil.createMonospacedFont(12));
    messages.setEditable(false);

    setServer(svr);

    quietOption.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean q = quietOption.isSelected();
            if (server != null) {
                server.setQuiet(q);
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();

    JButton clear = new JButton(new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            messages.setText("");
        }
    });

    final boolean[] follow = new boolean[] { true };
    final JCheckBox followTail = new JCheckBox("Follow", follow[0]);

    followTail.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            follow[0] = followTail.isSelected();
        }
    });

    final OutputStream os = new OutputStream() {
        @Override
        public void write(int b) throws IOException {
            char ch = (char) b;
            messages.append(new Character(ch).toString());
            if (ch == '\n' && follow[0]) {
                verticalScrollBar.setValue(verticalScrollBar.getMaximum());
            }
        }
    };

    TeePrintStream pso = new TeePrintStream(System.out, os);
    TeePrintStream pse = new TeePrintStream(System.err, os);

    System.setErr(pse);
    System.setOut(pso);

    Box box = Box.createHorizontalBox();
    box.add(clear);
    box.add(followTail);
    box.add(quietOption);
    box.add(Box.createHorizontalGlue());

    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(BorderLayout.NORTH, box);
    bottom.add(BorderLayout.SOUTH, statusInfoLine);

    Container cp = getContentPane();
    cp.add(BorderLayout.CENTER, scrollPane);
    cp.add(BorderLayout.SOUTH, bottom);

    pack();
    setSize(640, 480);

    final MemoryUsageMonitor mum = new MemoryUsageMonitor();
    mum.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            statusInfoLine.setMessage(mum.getMemoryUsage());
        }
    });

    if (server == null) {
        // If initial server is null, allow user to specify
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                serverStartAction.actionPerformed(null);
            }
        });
    } else {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                ensureDatabaseInitialisedThenStartServer();
            }
        });
    }
}