Example usage for javax.swing SpringLayout SpringLayout

List of usage examples for javax.swing SpringLayout SpringLayout

Introduction

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

Prototype

public SpringLayout() 

Source Link

Document

Constructs a new SpringLayout.

Usage

From source file:SpringBox.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *///from w w  w.  ja  v  a2s  .  com
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

    //Create and set up the window.
    JFrame frame = new JFrame("SpringBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Set up the content pane.
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new SpringLayout());

    //Add the buttons.
    contentPane.add(new JButton("Button 1"));
    contentPane.add(new JButton("Button 2"));
    contentPane.add(new JButton("Button 3"));
    contentPane.add(new JButton("Long-Named Button 4"));
    contentPane.add(new JButton("5"));

    //Lay out the buttons in one row and as many columns
    //as necessary, with 6 pixels of padding all around.
    SpringUtilities.makeCompactGrid(contentPane, 1, contentPane.getComponentCount(), 6, 6, 6, 6);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:components.SpinnerDemo4.java

public SpinnerDemo4() {
    super(new SpringLayout());

    String[] labels = { "Shade of Gray: " };
    int numPairs = labels.length;

    JSpinner spinner = addLabeledSpinner(this, labels[0], new GrayModel(170));
    spinner.setEditor(new GrayEditor(spinner));

    //Lay out the panel.
    SpringUtilities.makeCompactGrid(this, numPairs, 2, //rows, cols
            10, 10, //initX, initY
            6, 10); //xPad, yPad
}

From source file:components.SpinnerDemo.java

public SpinnerDemo(boolean cycleMonths) {
    super(new SpringLayout());

    String[] labels = { "Month: ", "Year: ", "Another Date: " };
    int numPairs = labels.length;
    Calendar calendar = Calendar.getInstance();
    JFormattedTextField ftf = null;

    //Add the first label-spinner pair.
    String[] monthStrings = getMonthStrings(); //get month names
    SpinnerListModel monthModel = null;
    if (cycleMonths) { //use custom model
        monthModel = new CyclingSpinnerListModel(monthStrings);
    } else { //use standard model
        monthModel = new SpinnerListModel(monthStrings);
    }/* www  .  j a  v a 2s  .  c o  m*/
    JSpinner spinner = addLabeledSpinner(this, labels[0], monthModel);
    //Tweak the spinner's formatted text field.
    ftf = getTextField(spinner);
    if (ftf != null) {
        ftf.setColumns(8); //specify more width than we need
        ftf.setHorizontalAlignment(JTextField.RIGHT);
    }

    //Add second label-spinner pair.
    int currentYear = calendar.get(Calendar.YEAR);
    SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value
            currentYear - 100, //min
            currentYear + 100, //max
            1); //step
    //If we're cycling, hook this model up to the month model.
    if (monthModel instanceof CyclingSpinnerListModel) {
        ((CyclingSpinnerListModel) monthModel).setLinkedModel(yearModel);
    }
    spinner = addLabeledSpinner(this, labels[1], yearModel);
    //Make the year be formatted without a thousands separator.
    spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));

    //Add the third label-spinner pair.
    Date initDate = calendar.getTime();
    calendar.add(Calendar.YEAR, -100);
    Date earliestDate = calendar.getTime();
    calendar.add(Calendar.YEAR, 200);
    Date latestDate = calendar.getTime();
    SpinnerModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);//ignored for user input
    spinner = addLabeledSpinner(this, labels[2], dateModel);
    spinner.setEditor(new JSpinner.DateEditor(spinner, "MM/yyyy"));

    //Lay out the panel.
    SpringUtilities.makeCompactGrid(this, numPairs, 2, //rows, cols
            10, 10, //initX, initY
            6, 10); //xPad, yPad
}

From source file:com.romraider.logger.ecu.ui.tab.LoggerChartPanel.java

public LoggerChartPanel(String labelX, String labelY) {
    super(new SpringLayout());
    checkNotNull(labelX, labelY);/*from  w  ww .java2s. c o  m*/
    this.labelX = labelX;
    this.labelY = labelY;
    addChart();
}

From source file:components.SpinnerDemo3.java

public SpinnerDemo3(boolean cycleMonths) {
    super(new SpringLayout());

    String[] labels = { "Month: ", "Year: ", "Another Date: " };
    int numPairs = labels.length;
    calendar = Calendar.getInstance();
    JFormattedTextField ftf = null;

    //Add the first label-spinner pair.
    String[] monthStrings = getMonthStrings(); //get month names
    SpinnerListModel monthModel = null;
    if (cycleMonths) { //use custom model
        monthModel = new CyclingSpinnerListModel(monthStrings);
    } else { //use standard model
        monthModel = new SpinnerListModel(monthStrings);
    }/*w ww.  j  ava2s.c  om*/
    JSpinner spinner = addLabeledSpinner(this, labels[0], monthModel);
    //Tweak the spinner's formatted text field.
    ftf = getTextField(spinner);
    if (ftf != null) {
        ftf.setColumns(8); //specify more width than we need
        ftf.setHorizontalAlignment(JTextField.RIGHT);
    }

    //Add second label-spinner pair.
    int currentYear = calendar.get(Calendar.YEAR);
    SpinnerModel yearModel = new SpinnerNumberModel(currentYear, //initial value
            currentYear - 100, //min
            currentYear + 100, //max
            1); //step
    //If we're cycling, hook this model up to the month model.
    if (monthModel instanceof CyclingSpinnerListModel) {
        ((CyclingSpinnerListModel) monthModel).setLinkedModel(yearModel);
    }
    spinner = addLabeledSpinner(this, labels[1], yearModel);
    //Make the year be formatted without a thousands separator.
    spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));

    //Add the third label-spinner pair.
    Date initDate = calendar.getTime();
    calendar.add(Calendar.YEAR, -100);
    Date earliestDate = calendar.getTime();
    calendar.add(Calendar.YEAR, 200);
    Date latestDate = calendar.getTime();
    SpinnerDateModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);//ignored for user input
    dateSpinner = spinner = addLabeledSpinner(this, labels[2], dateModel);
    spinner.setEditor(new JSpinner.DateEditor(spinner, "MM/yyyy"));
    //Tweak the spinner's formatted text field.
    ftf = getTextField(spinner);
    if (ftf != null) {
        ftf.setHorizontalAlignment(JTextField.RIGHT);
        ftf.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 3));
    }
    spinner.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
    //XXX: No easy way to get to the buttons and change their border.
    setSeasonalColor(dateModel.getDate()); //initialize color

    //Listen for changes on the date spinner.
    dateSpinner.addChangeListener(this);

    //Lay out the panel.
    SpringUtilities.makeCompactGrid(this, numPairs, 2, //rows, cols
            10, 10, //initX, initY
            6, 10); //xPad, yPad
}

From source file:org.gumtree.vis.awt.AbstractPlotEditor.java

private JPanel createHelpPanel() {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = plot.getHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);/*w ww .  j  a  va 2  s  . c o m*/
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;
}

From source file:com.awesomecoding.minetestlauncher.Main.java

private void initialize() {
    fileGetter = new FileGetter(userhome + "\\minetest\\temp\\");
    latest = fileGetter.getContents("http://socialmelder.com/minetest/latest.txt", true);
    currentVersion = latest.split("\n")[0];
    changelog = fileGetter.getContents("http://socialmelder.com/minetest/changelog.html", false);

    try {//from   ww w .j  av  a2 s .  c o  m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    frmMinetestLauncherV = new JFrame();
    frmMinetestLauncherV.setResizable(false);
    frmMinetestLauncherV.setIconImage(Toolkit.getDefaultToolkit()
            .getImage(Main.class.getResource("/com/awesomecoding/minetestlauncher/icon.png")));
    frmMinetestLauncherV.setTitle("Minetest Launcher (Version 0.1)");
    frmMinetestLauncherV.setBounds(100, 100, 720, 480);
    frmMinetestLauncherV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout springLayout = new SpringLayout();
    frmMinetestLauncherV.getContentPane().setLayout(springLayout);

    final JProgressBar progressBar = new JProgressBar();
    springLayout.putConstraint(SpringLayout.WEST, progressBar, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, progressBar, -10, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, progressBar, -130, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(progressBar);

    final JButton btnDownloadPlay = new JButton("Play!");
    springLayout.putConstraint(SpringLayout.WEST, btnDownloadPlay, 6, SpringLayout.EAST, progressBar);
    springLayout.putConstraint(SpringLayout.SOUTH, btnDownloadPlay, 0, SpringLayout.SOUTH, progressBar);
    springLayout.putConstraint(SpringLayout.EAST, btnDownloadPlay, -10, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(btnDownloadPlay);

    final JLabel label = new JLabel("Ready to play!");
    springLayout.putConstraint(SpringLayout.WEST, label, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, btnDownloadPlay, 0, SpringLayout.NORTH, label);
    springLayout.putConstraint(SpringLayout.SOUTH, label, -37, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, progressBar, 6, SpringLayout.SOUTH, label);
    frmMinetestLauncherV.getContentPane().add(label);

    JTextPane txtpnNewFeatures = new JTextPane();
    txtpnNewFeatures.setBackground(SystemColor.window);
    springLayout.putConstraint(SpringLayout.NORTH, txtpnNewFeatures, 10, SpringLayout.NORTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, txtpnNewFeatures, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, txtpnNewFeatures, -10, SpringLayout.NORTH, btnDownloadPlay);
    springLayout.putConstraint(SpringLayout.EAST, txtpnNewFeatures, 0, SpringLayout.EAST, btnDownloadPlay);
    txtpnNewFeatures.setEditable(false);
    txtpnNewFeatures.setContentType("text/html");
    txtpnNewFeatures.setText(changelog);
    txtpnNewFeatures.setFont(new Font("Tahoma", Font.PLAIN, 12));
    frmMinetestLauncherV.getContentPane().add(txtpnNewFeatures);

    File file = new File(userhome + "\\minetest\\version.txt");

    if (!file.exists())
        newVersion = true;
    else {
        String version = fileGetter.getLocalContents(file, false);
        if (!version.equals(currentVersion))
            newVersion = true;
    }

    if (newVersion) {
        label.setText("New Version Available! (" + currentVersion + ")");
        btnDownloadPlay.setText("Download & Play");

        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                Thread t = new Thread() {
                    public void run() {
                        File file = new File(userhome + "\\minetest\\version.txt");
                        String version = fileGetter.getLocalContents(file, false);
                        try {
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\minetest-" + version));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        fileGetter.download(latest.split("\n")[1], userhome + "\\minetest\\temp\\",
                                "minetest.zip", label, progressBar, btnDownloadPlay, currentVersion);
                        try {
                            label.setText("Cleaning up...");
                            btnDownloadPlay.setText("Cleaning up...");
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\temp"));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        System.exit(0);
                    }
                };
                t.start();
            }
        });
    } else {
        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                try {
                    label.setText("Launching...");
                    btnDownloadPlay.setEnabled(false);
                    btnDownloadPlay.setText("Launching...");
                    File file = new File(userhome + "\\minetest\\version.txt");
                    String version = fileGetter.getLocalContents(file, false);
                    Runtime.getRuntime()
                            .exec(userhome + "\\minetest\\minetest-" + version + "\\bin\\minetest.exe");
                    System.exit(0);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        progressBar.setValue(100);
    }
}

From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java

public GraphUpdateHandler(final JPanel panel) {
    this.graphPanel = new JPanel(new SpringLayout());
    final JCheckBox combinedCheckbox = new JCheckBox("Combine Graphs", combinedChart);
    combinedCheckbox.addActionListener(new CombinedActionListener(combinedCheckbox));
    JToggleButton playPauseButton = new JToggleButton("Pause Graphs");
    playPauseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            paused = !paused;//from  w w w.  j av a2s .c  o m
            if (paused) {
                pauseStartTime = System.currentTimeMillis();
            } else {
                startTime = startTime + (System.currentTimeMillis() - pauseStartTime);
            }
        }
    });
    panel.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(getKeyStroke("F12"), "toggleCombineGraphs");
    panel.getActionMap().put("toggleCombineGraphs", new AbstractAction() {
        private static final long serialVersionUID = 1540427179539775534L;

        public void actionPerformed(ActionEvent e) {
            combinedCheckbox.doClick();
        }
    });
    JPanel controlPanel = new JPanel();
    controlPanel.add(combinedCheckbox);
    controlPanel.add(playPauseButton);
    panel.add(controlPanel, NORTH);
    panel.add(this.graphPanel, CENTER);
}

From source file:org.gdms.usm.view.ProgressFrame.java

public ProgressFrame(Step s, boolean modifyThresholds) {
    super("Progress");
    simulation = s;//from  w ww.j  av a2  s.com
    s.registerStepListener(this);
    stepSeconds = new LinkedList<Integer>();

    s.getManager().setModifyThresholds(modifyThresholds);
    s.getManager().setAdvisor(this);

    JPanel statusPanel = new JPanel(new BorderLayout());
    JPanel globalPanel = new JPanel(new SpringLayout());

    //Time elapsed panel
    JPanel timePanel = new JPanel(new BorderLayout(5, 5));
    final JLabel timeLabel = new JLabel("00:00:00", SwingConstants.CENTER);
    timeLabel.setFont(new Font("Serif", Font.BOLD, 45));
    timePanel.add(timeLabel, BorderLayout.SOUTH);
    JLabel elapsed = new JLabel("Time Elapsed :", SwingConstants.CENTER);
    timePanel.add(elapsed, BorderLayout.NORTH);
    statusPanel.add(timePanel, BorderLayout.NORTH);

    ActionListener timerListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            totalSeconds++;
            int hours = totalSeconds / 3600;
            String hourss;
            if (hours < 10) {
                hourss = "0" + hours;
            } else {
                hourss = "" + hours;
            }
            int minutes = (totalSeconds % 3600) / 60;
            String minutess;
            if (minutes < 10) {
                minutess = "0" + minutes;
            } else {
                minutess = "" + minutes;
            }
            int seconds = totalSeconds % 60;
            String secondss;
            if (seconds < 10) {
                secondss = "0" + seconds;
            } else {
                secondss = seconds + "";
            }
            timeLabel.setText(hourss + ":" + minutess + ":" + secondss);
        }
    };
    timer = new Timer(1000, timerListener);
    timer.start();

    //Turn progress panel
    JPanel turnPanel = new JPanel(new BorderLayout(5, 5));
    JLabel turnLabel = new JLabel("Current Step :", SwingConstants.CENTER);
    turnPanel.add(turnLabel, BorderLayout.NORTH);
    currentTurn = new JLabel("Init", SwingConstants.CENTER);
    currentTurn.setFont(new Font("Serif", Font.BOLD, 30));
    turnPanel.add(currentTurn, BorderLayout.SOUTH);
    globalPanel.add(turnPanel);

    //Movers panel
    JPanel moversPanel = new JPanel(new BorderLayout(5, 5));
    JLabel moversLabel = new JLabel("Last movers count :", SwingConstants.CENTER);
    moversPanel.add(moversLabel, BorderLayout.NORTH);
    lastMoversCount = new JLabel("Init", SwingConstants.CENTER);
    lastMoversCount.setFont(new Font("Serif", Font.BOLD, 30));
    moversPanel.add(lastMoversCount, BorderLayout.SOUTH);
    globalPanel.add(moversPanel);

    //Initial population panel
    JPanel initPopPanel = new JPanel(new BorderLayout(5, 5));
    JLabel initialPopulationLabel = new JLabel("Initial population :", SwingConstants.CENTER);
    initPopPanel.add(initialPopulationLabel, BorderLayout.NORTH);
    initialPopulationCount = new JLabel("Init", SwingConstants.CENTER);
    initialPopulationCount.setFont(new Font("Serif", Font.BOLD, 30));
    initPopPanel.add(initialPopulationCount, BorderLayout.SOUTH);
    globalPanel.add(initPopPanel);

    //Current population panel
    JPanel curPopPanel = new JPanel(new BorderLayout(5, 5));
    JLabel currentPopulationLabel = new JLabel("Current population :", SwingConstants.CENTER);
    curPopPanel.add(currentPopulationLabel, BorderLayout.NORTH);
    currentPopulation = new JLabel("Init", SwingConstants.CENTER);
    currentPopulation.setFont(new Font("Serif", Font.BOLD, 30));
    curPopPanel.add(currentPopulation, BorderLayout.SOUTH);
    globalPanel.add(curPopPanel);

    //Dead panel
    JPanel deadPanel = new JPanel(new BorderLayout(5, 5));
    JLabel deadLabel = new JLabel("Last death toll :", SwingConstants.CENTER);
    deadPanel.add(deadLabel, BorderLayout.NORTH);
    lastDeathToll = new JLabel("Init", SwingConstants.CENTER);
    lastDeathToll.setFont(new Font("Serif", Font.BOLD, 30));
    deadPanel.add(lastDeathToll, BorderLayout.SOUTH);
    globalPanel.add(deadPanel);

    //Newborn panel
    JPanel newbornPanel = new JPanel(new BorderLayout(5, 5));
    JLabel newbornLabel = new JLabel("Last newborn count :", SwingConstants.CENTER);
    newbornPanel.add(newbornLabel, BorderLayout.NORTH);
    lastNewbornCount = new JLabel("Init", SwingConstants.CENTER);
    lastNewbornCount.setFont(new Font("Serif", Font.BOLD, 30));
    newbornPanel.add(lastNewbornCount, BorderLayout.SOUTH);
    globalPanel.add(newbornPanel);

    SpringUtilities.makeCompactGrid(globalPanel, 3, 2, 5, 5, 20, 10);
    statusPanel.add(globalPanel, BorderLayout.SOUTH);

    add(statusPanel, BorderLayout.WEST);

    //Graph tabbed pane
    JTabbedPane tabbedPane = new JTabbedPane();
    timeChart = new XYSeries("Step time", true, false);
    tabbedPane.addTab("Step time", createChartPanel("Step time", timeChart));
    currentPopulationChart = new XYSeries("Population", true, false);
    tabbedPane.addTab("Population", createChartPanel("Population", currentPopulationChart));
    deathTollChart = new XYSeries("Deaths", true, false);
    tabbedPane.addTab("Deaths", createChartPanel("Deaths", deathTollChart));
    newbornCountChart = new XYSeries("Newborn", true, false);
    tabbedPane.addTab("Newborn", createChartPanel("Newborn", newbornCountChart));
    moversCountChart = new XYSeries("Movers", true, false);
    tabbedPane.addTab("Movers", createChartPanel("Movers", moversCountChart));
    add(tabbedPane, BorderLayout.EAST);

    getRootPane().setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 10));
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
}

From source file:components.TableFilterDemo.java

public TableFilterDemo() {
    super();//from w w w . j a  va2  s.c om
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    //Create a table with a sorter.
    MyTableModel model = new MyTableModel();
    sorter = new TableRowSorter<MyTableModel>(model);
    table = new JTable(model);
    table.setRowSorter(sorter);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //For the purposes of this example, better to have a single
    //selection.
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    //When selection changes, provide user with row numbers for
    //both view and model.
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            int viewRow = table.getSelectedRow();
            if (viewRow < 0) {
                //Selection got filtered away.
                statusText.setText("");
            } else {
                int modelRow = table.convertRowIndexToModel(viewRow);
                statusText.setText(String.format("Selected Row in view: %d. " + "Selected Row in model: %d.",
                        viewRow, modelRow));
            }
        }
    });

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);

    //Create a separate form for filterText and statusText
    JPanel form = new JPanel(new SpringLayout());
    JLabel l1 = new JLabel("Filter Text:", SwingConstants.TRAILING);
    form.add(l1);
    filterText = new JTextField();
    //Whenever filterText changes, invoke newFilter.
    filterText.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            newFilter();
        }

        public void insertUpdate(DocumentEvent e) {
            newFilter();
        }

        public void removeUpdate(DocumentEvent e) {
            newFilter();
        }
    });
    l1.setLabelFor(filterText);
    form.add(filterText);
    JLabel l2 = new JLabel("Status:", SwingConstants.TRAILING);
    form.add(l2);
    statusText = new JTextField();
    l2.setLabelFor(statusText);
    form.add(statusText);
    SpringUtilities.makeCompactGrid(form, 2, 2, 6, 6, 6, 6);
    add(form);
}