Example usage for javax.swing JSplitPane add

List of usage examples for javax.swing JSplitPane add

Introduction

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

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:org.jfree.chart.demo.selection.SelectionDemo1.java

/**
 * A demonstration application showing how to create a simple time series
 * chart. This example uses monthly data.
 * //from w w w  .  j  a v  a2 s.  c  o m
 * @param title  the frame title.
 */
public SelectionDemo1(String title) {
    super(title);
    ChartPanel chartPanel = (ChartPanel) createDemoPanel();
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    JFreeChart chart = chartPanel.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    this.dataset = (TimeSeriesCollection) plot.getDataset();
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.add(chartPanel);

    this.model = new DefaultTableModel(new String[] { "Series:", "Item:", "Period:", "Value:" }, 0);
    this.table = new JTable(this.model);
    TableColumnModel tcm = this.table.getColumnModel();
    tcm.getColumn(3).setCellRenderer(new NumberCellRenderer());
    JPanel p = new JPanel(new BorderLayout());
    JScrollPane scroller = new JScrollPane(this.table);
    p.add(scroller);
    p.setBorder(BorderFactory.createCompoundBorder(new TitledBorder("Selected Items: "),
            new EmptyBorder(4, 4, 4, 4)));
    split.add(p);
    setContentPane(split);

}

From source file:org.datacleaner.widgets.result.UniqueKeyCheckAnalyzerResultSwingRenderer.java

@Override
public JComponent render(UniqueKeyCheckAnalyzerResult result) {
    final int nullCount = result.getNullCount();
    final int nonUniqueCount = result.getNonUniqueCount();

    final DefaultKeyedValues keyedValues = new DefaultKeyedValues();
    keyedValues.addValue("Unique keys", result.getUniqueCount());

    final List<Title> subTitles = new ArrayList<Title>();
    subTitles.add(new ShortTextTitle("Row count: " + result.getRowCount()));
    subTitles.add(new ShortTextTitle("Unique key count: " + result.getUniqueCount()));

    if (nonUniqueCount > 0) {
        keyedValues.addValue("Non-unique keys", nonUniqueCount);
        subTitles.add(new ShortTextTitle("Non-unique key count: " + nonUniqueCount));
    }// ww w .  ja v  a2 s .  c o  m

    final String title;
    if (nullCount == 0) {
        title = "Unique and non-unique keys";
    } else {
        keyedValues.addValue(LabelUtils.NULL_LABEL, nullCount);
        title = "Unique, non-unique and <null> keys";
        subTitles.add(new ShortTextTitle("<null> key count: " + result.getNullCount()));
    }

    final DefaultPieDataset dataset = new DefaultPieDataset(keyedValues);
    final JFreeChart chart = ChartFactory.createRingChart(title, dataset, true, true, false);

    chart.setSubtitles(subTitles);

    ChartUtils.applyStyles(chart);
    ChartPanel chartPanel = ChartUtils.createPanel(chart, false);

    final DCPanel leftPanel = new DCPanel();
    leftPanel.setLayout(new VerticalLayout());
    leftPanel.add(WidgetUtils.decorateWithShadow(chartPanel));

    final Map<String, Integer> samples = result.getNonUniqueSamples();
    if (samples == null || samples.isEmpty()) {
        return leftPanel;
    }

    final DefaultTableModel samplesTableModel = new DefaultTableModel(new String[] { "Key", "Count" }, 0);
    for (final Entry<String, Integer> entry : samples.entrySet()) {
        final String key = entry.getKey();
        final Integer count = entry.getValue();
        samplesTableModel.addRow(new Object[] { key, count });
    }
    final DCTable samplesTable = new DCTable(samplesTableModel);

    final DCPanel rightPanel = new DCPanel();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(DCLabel.dark("Sample non-unique keys:"));
    rightPanel.add(samplesTable.toPanel(), BorderLayout.CENTER);

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setOpaque(false);
    split.add(leftPanel);
    split.add(rightPanel);
    split.setDividerLocation(550);

    return split;
}

From source file:org.eobjects.datacleaner.widgets.result.UniqueKeyCheckAnalyzerResultSwingRenderer.java

@Override
public JComponent render(UniqueKeyCheckAnalyzerResult result) {
    final int nullCount = result.getNullCount();
    final int nonUniqueCount = result.getNonUniqueCount();

    final DefaultKeyedValues keyedValues = new DefaultKeyedValues();
    keyedValues.addValue("Unique keys", result.getUniqueCount());

    final List<Title> subTitles = new ArrayList<Title>();
    subTitles.add(new ShortTextTitle("Row count: " + result.getRowCount()));
    subTitles.add(new ShortTextTitle("Unique key count: " + result.getUniqueCount()));

    if (nonUniqueCount > 0) {
        keyedValues.addValue("Non-unique keys", nonUniqueCount);
        subTitles.add(new ShortTextTitle("Non-unique key count: " + nonUniqueCount));
    }//  w w w  .ja  va2s. co  m

    final String title;
    if (nullCount == 0) {
        title = "Unique and non-unique keys";
    } else {
        keyedValues.addValue(LabelUtils.NULL_LABEL, nullCount);
        title = "Unique, non-unique and <null> keys";
        subTitles.add(new ShortTextTitle("<null> key count: " + result.getNullCount()));
    }

    final DefaultPieDataset dataset = new DefaultPieDataset(keyedValues);
    final JFreeChart chart = ChartFactory.createRingChart(title, dataset, true, true, false);

    chart.setSubtitles(subTitles);

    ChartUtils.applyStyles(chart);
    ChartPanel chartPanel = new ChartPanel(chart);

    final DCPanel leftPanel = new DCPanel();
    leftPanel.setLayout(new VerticalLayout());
    leftPanel.add(WidgetUtils.decorateWithShadow(chartPanel, true, 4));

    final Map<String, Integer> samples = result.getNonUniqueSamples();
    if (samples == null || samples.isEmpty()) {
        return leftPanel;
    }

    final DefaultTableModel samplesTableModel = new DefaultTableModel(new String[] { "Key", "Count" }, 0);
    for (final Entry<String, Integer> entry : samples.entrySet()) {
        final String key = entry.getKey();
        final Integer count = entry.getValue();
        samplesTableModel.addRow(new Object[] { key, count });
    }
    final DCTable samplesTable = new DCTable(samplesTableModel);

    final DCPanel rightPanel = new DCPanel();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(DCLabel.dark("Sample non-unique keys:"));
    rightPanel.add(samplesTable.toPanel(), BorderLayout.CENTER);

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setOpaque(false);
    split.add(leftPanel);
    split.add(rightPanel);
    split.setDividerLocation(550);

    return split;
}

From source file:org.eobjects.datacleaner.widgets.result.DateGapAnalyzerResultSwingRenderer.java

@Override
public JComponent render(DateGapAnalyzerResult result) {

    final TaskSeriesCollection dataset = new TaskSeriesCollection();
    final Set<String> groupNames = result.getGroupNames();
    final TaskSeries completeDurationTaskSeries = new TaskSeries(LABEL_COMPLETE_DURATION);
    final TaskSeries gapsTaskSeries = new TaskSeries(LABEL_GAPS);
    final TaskSeries overlapsTaskSeries = new TaskSeries(LABEL_OVERLAPS);
    for (final String groupName : groupNames) {
        final String groupDisplayName;

        if (groupName == null) {
            if (groupNames.size() == 1) {
                groupDisplayName = "All";
            } else {
                groupDisplayName = LabelUtils.NULL_LABEL;
            }// w  w  w.j  a  v a 2s . com
        } else {
            groupDisplayName = groupName;
        }

        final TimeInterval completeDuration = result.getCompleteDuration(groupName);
        final Task completeDurationTask = new Task(groupDisplayName,
                createTimePeriod(completeDuration.getFrom(), completeDuration.getTo()));
        completeDurationTaskSeries.add(completeDurationTask);

        // plot gaps
        {
            final SortedSet<TimeInterval> gaps = result.getGaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : gaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    gapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " gap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }

        // plot overlaps
        {
            final SortedSet<TimeInterval> overlaps = result.getOverlaps(groupName);

            int i = 1;
            Task rootTask = null;
            for (TimeInterval interval : overlaps) {
                final TimePeriod timePeriod = createTimePeriod(interval.getFrom(), interval.getTo());

                if (rootTask == null) {
                    rootTask = new Task(groupDisplayName, timePeriod);
                    overlapsTaskSeries.add(rootTask);
                } else {
                    Task task = new Task(groupDisplayName + " overlap" + i, timePeriod);
                    rootTask.addSubtask(task);
                }

                i++;
            }
        }
    }
    dataset.add(overlapsTaskSeries);
    dataset.add(gapsTaskSeries);
    dataset.add(completeDurationTaskSeries);

    final SlidingGanttCategoryDataset slidingDataset = new SlidingGanttCategoryDataset(dataset, 0,
            GROUPS_VISIBLE);

    final JFreeChart chart = ChartFactory.createGanttChart(
            "Date gaps and overlaps in " + result.getFromColumnName() + " / " + result.getToColumnName(),
            result.getGroupColumnName(), "Time", slidingDataset, true, true, false);
    ChartUtils.applyStyles(chart);

    // make sure the 3 timeline types have correct coloring
    {
        final CategoryPlot plot = (CategoryPlot) chart.getPlot();

        plot.setDrawingSupplier(new DCDrawingSupplier(WidgetUtils.ADDITIONAL_COLOR_GREEN_BRIGHT,
                WidgetUtils.ADDITIONAL_COLOR_RED_BRIGHT, WidgetUtils.BG_COLOR_BLUE_BRIGHT));
    }

    final ChartPanel chartPanel = new ChartPanel(chart);

    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            Cursor cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
            ChartEntity entity = event.getEntity();
            if (entity instanceof PlotEntity) {
                cursor = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
            }
            chartPanel.setCursor(cursor);
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            // do nothing
        }
    });

    final int visibleLines = Math.min(GROUPS_VISIBLE, groupNames.size());

    chartPanel.setPreferredSize(new Dimension(0, visibleLines * 50 + 200));

    final JComponent decoratedChartPanel;

    StringBuilder chartDescription = new StringBuilder();
    chartDescription
            .append("<html><p>The chart displays the recorded timeline based on FROM and TO dates.<br/><br/>");
    chartDescription.append(
            "The <b>red items</b> represent gaps in the timeline and the <b>green items</b> represent points in the timeline where more than one record show activity.<br/><br/>");
    chartDescription.append(
            "You can <b>zoom in</b> by clicking and dragging the area that you want to examine in further detail.");

    if (groupNames.size() > GROUPS_VISIBLE) {
        final JScrollBar scroll = new JScrollBar(JScrollBar.VERTICAL);
        scroll.setMinimum(0);
        scroll.setMaximum(groupNames.size());
        scroll.addAdjustmentListener(new AdjustmentListener() {

            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                int value = e.getAdjustable().getValue();
                slidingDataset.setFirstCategoryIndex(value);
            }
        });

        chartPanel.addMouseWheelListener(new MouseWheelListener() {

            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                int scrollType = e.getScrollType();
                if (scrollType == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                    int wheelRotation = e.getWheelRotation();
                    scroll.setValue(scroll.getValue() + wheelRotation);
                }
            }
        });

        final DCPanel outerPanel = new DCPanel();
        outerPanel.setLayout(new BorderLayout());
        outerPanel.add(chartPanel, BorderLayout.CENTER);
        outerPanel.add(scroll, BorderLayout.EAST);
        chartDescription.append("<br/><br/>Use the right <b>scrollbar</b> to scroll up and down on the chart.");
        decoratedChartPanel = outerPanel;

    } else {
        decoratedChartPanel = chartPanel;
    }

    chartDescription.append("</p></html>");

    final JLabel chartDescriptionLabel = new JLabel(chartDescription.toString());

    chartDescriptionLabel.setBorder(new EmptyBorder(4, 10, 4, 10));

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.add(decoratedChartPanel);
    split.add(chartDescriptionLabel);
    split.setDividerLocation(550);

    return split;
}

From source file:org.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java

public JSplitPane renderGroupResult(final ValueCountingAnalyzerResult result) {
    final Integer distinctCount = result.getDistinctCount();
    final Integer unexpectedValueCount = result.getUnexpectedValueCount();
    final int totalCount = result.getTotalCount();

    _valueCounts = result.getReducedValueFrequencies(_preferredSlices);
    _valueCounts = moveUniqueToEnd(_valueCounts);

    for (ValueFrequency valueCount : _valueCounts) {
        setDataSetValue(valueCount.getName(), valueCount.getCount());
    }/*from w w w  .j  a  va2  s . c  om*/

    logger.info("Rendering with {} slices", getDataSetItemCount());
    drillToOverview(result);

    // chart for display of the dataset
    String title = "Value distribution of " + _groupOrColumnName;
    final JFreeChart chart = ChartFactory.createBarChart(title, "Value", "Count", _dataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    List<Title> titles = new ArrayList<Title>();
    titles.add(new ShortTextTitle("Total count: " + totalCount));
    if (distinctCount != null) {
        titles.add(new ShortTextTitle("Distinct count: " + distinctCount));
    }
    if (unexpectedValueCount != null) {
        titles.add(new ShortTextTitle("Unexpected value count: " + unexpectedValueCount));
    }
    chart.setSubtitles(titles);

    ChartUtils.applyStyles(chart);

    // code-block for tweaking style and coloring of chart
    {
        final CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.getDomainAxis().setVisible(false);

        int colorIndex = 0;
        for (int i = 0; i < getDataSetItemCount(); i++) {
            final String key = getDataSetKey(i);
            final Color color;
            final String upperCaseKey = key.toUpperCase();
            if (_valueColorMap.containsKey(upperCaseKey)) {
                color = _valueColorMap.get(upperCaseKey);
            } else {
                if (i == getDataSetItemCount() - 1) {
                    // the last color should not be the same as the first
                    if (colorIndex == 0) {
                        colorIndex++;
                    }
                }

                Color colorCandidate = SLICE_COLORS[colorIndex];
                int darkAmount = i / SLICE_COLORS.length;
                for (int j = 0; j < darkAmount; j++) {
                    colorCandidate = WidgetUtils.slightlyDarker(colorCandidate);
                }
                color = colorCandidate;

                colorIndex++;
                if (colorIndex >= SLICE_COLORS.length) {
                    colorIndex = 0;
                }
            }

            plot.getRenderer().setSeriesPaint(i, color);
        }
    }

    final ChartPanel chartPanel = ChartUtils.createPanel(chart, false);

    final DCPanel leftPanel = new DCPanel();
    leftPanel.setLayout(new VerticalLayout());
    leftPanel.add(WidgetUtils.decorateWithShadow(chartPanel));

    _backButton.setMargin(new Insets(0, 0, 0, 0));
    _backButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            drillToOverview(result);
        }
    });

    _rightPanel.setLayout(new VerticalLayout());
    _rightPanel.add(_backButton);
    _rightPanel.add(WidgetUtils.decorateWithShadow(_table.toPanel()));

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setOpaque(false);
    split.add(leftPanel);
    split.add(_rightPanel);
    split.setDividerLocation(550);

    return split;
}

From source file:org.eobjects.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java

public JSplitPane renderGroupResult(final ValueCountingAnalyzerResult result) {
    final Integer distinctCount = result.getDistinctCount();
    final Integer unexpectedValueCount = result.getUnexpectedValueCount();
    final int totalCount = result.getTotalCount();

    _valueCounts = result.getReducedValueFrequencies(_preferredSlices);
    for (ValueFrequency valueCount : _valueCounts) {
        setDataSetValue(valueCount.getName(), valueCount.getCount());
    }//from  www  .  j  a v  a2  s. c o m

    logger.info("Rendering with {} slices", getDataSetItemCount());
    drillToOverview(result);

    // chart for display of the dataset
    String title = "Value distribution of " + _groupOrColumnName;
    final JFreeChart chart = ChartFactory.createBarChart(title, "Value", "Count", _dataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    List<Title> titles = new ArrayList<Title>();
    titles.add(new ShortTextTitle("Total count: " + totalCount));
    if (distinctCount != null) {
        titles.add(new ShortTextTitle("Distinct count: " + distinctCount));
    }
    if (unexpectedValueCount != null) {
        titles.add(new ShortTextTitle("Unexpected value count: " + unexpectedValueCount));
    }
    chart.setSubtitles(titles);

    ChartUtils.applyStyles(chart);

    // code-block for tweaking style and coloring of chart
    {
        final CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.getDomainAxis().setVisible(false);

        int colorIndex = 0;
        for (int i = 0; i < getDataSetItemCount(); i++) {
            final String key = getDataSetKey(i);
            final Color color;
            final String upperCaseKey = key.toUpperCase();
            if (_valueColorMap.containsKey(upperCaseKey)) {
                color = _valueColorMap.get(upperCaseKey);
            } else {
                if (i == getDataSetItemCount() - 1) {
                    // the last color should not be the same as the first
                    if (colorIndex == 0) {
                        colorIndex++;
                    }
                }

                Color colorCandidate = SLICE_COLORS[colorIndex];
                int darkAmount = i / SLICE_COLORS.length;
                for (int j = 0; j < darkAmount; j++) {
                    colorCandidate = WidgetUtils.slightlyDarker(colorCandidate);
                }
                color = colorCandidate;

                colorIndex++;
                if (colorIndex >= SLICE_COLORS.length) {
                    colorIndex = 0;
                }
            }

            plot.getRenderer().setSeriesPaint(i, color);
        }
    }

    final ChartPanel chartPanel = new ChartPanel(chart);

    // chartPanel.addChartMouseListener(new ChartMouseListener() {
    //
    // @Override
    // public void chartMouseMoved(ChartMouseEvent event) {
    // ChartEntity entity = event.getEntity();
    // if (entity instanceof PieSectionEntity) {
    // PieSectionEntity pieSectionEntity = (PieSectionEntity) entity;
    // String sectionKey = (String) pieSectionEntity.getSectionKey();
    // if (_groups.containsKey(sectionKey)) {
    // chartPanel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    // } else {
    // chartPanel.setCursor(Cursor.getDefaultCursor());
    // }
    // } else {
    // chartPanel.setCursor(Cursor.getDefaultCursor());
    // }
    // }
    //
    // @Override
    // public void chartMouseClicked(ChartMouseEvent event) {
    // ChartEntity entity = event.getEntity();
    // if (entity instanceof PieSectionEntity) {
    // PieSectionEntity pieSectionEntity = (PieSectionEntity) entity;
    // String sectionKey = (String) pieSectionEntity.getSectionKey();
    // if (_groups.containsKey(sectionKey)) {
    // drillToGroup(result, sectionKey, true);
    // }
    // }
    // }
    // });

    final DCPanel leftPanel = new DCPanel();
    leftPanel.setLayout(new VerticalLayout());
    leftPanel.add(WidgetUtils.decorateWithShadow(chartPanel, true, 4));

    _backButton.setMargin(new Insets(0, 0, 0, 0));
    _backButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            drillToOverview(result);
        }
    });

    final DCPanel rightPanel = new DCPanel();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(_backButton, BorderLayout.NORTH);
    rightPanel.add(_table.toPanel(), BorderLayout.CENTER);

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setOpaque(false);
    split.add(leftPanel);
    split.add(rightPanel);
    split.setDividerLocation(550);

    return split;
}

From source file:com.k42b3.sacmis.Sacmis.java

public Sacmis(String path, String file, int exitCode, boolean writerStdIn) throws Exception {
    this.path = path;
    this.file = file;
    this.exitCode = exitCode;
    this.writerStdIn = writerStdIn;

    this.setTitle("sacmis (version: " + ver + ")");

    this.setLocation(100, 100);

    this.setSize(600, 500);

    this.setMinimumSize(this.getSize());

    // arguments/*from   w  w  w  .jav a2  s  .  co m*/
    JPanel panelArgs = new JPanel();

    panelArgs.setLayout(new BorderLayout());

    panelArgs.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    this.args = new Args();

    this.args.setText(file);

    panelArgs.add(this.args, BorderLayout.CENTER);

    this.add(panelArgs, BorderLayout.NORTH);

    // main panel
    JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);

    this.in = new In();

    JScrollPane scrIn = new JScrollPane(this.in);

    scrIn.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    scrIn.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    scrIn.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    sp.add(scrIn);

    this.out = new Out();

    JScrollPane scrOut = new JScrollPane(this.out);

    scrOut.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    scrOut.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    scrOut.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    sp.add(scrOut);

    this.add(sp, BorderLayout.CENTER);

    // toolbar
    this.toolbar = new Toolbar();

    this.toolbar.getRun().addActionListener(new runHandler());
    this.toolbar.getReset().addActionListener(new resetHandler());
    this.toolbar.getAbout().addActionListener(new aboutHandler());
    this.toolbar.getExit().addActionListener(new exitHandler());

    this.getContentPane().add(this.toolbar, BorderLayout.SOUTH);

    this.setVisible(true);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.loadFile();
}

From source file:events.ListSelectionDemo.java

public ListSelectionDemo() {
    super(new BorderLayout());

    String[] listData = { "one", "two", "three", "four", "five", "six", "seven" };
    String[] columnNames = { "French", "Spanish", "Italian" };
    list = new JList(listData);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);/*  ww w .  jav  a 2  s .  c  om*/
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    //Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    //Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);

    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    //topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(100, 50));
    topHalf.setPreferredSize(new Dimension(100, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    //XXX: next line needed if bottomHalf is a scroll pane:
    //bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
}

From source file:ListSelectionDemo.java

public ListSelectionDemo() {
    super(new BorderLayout());

    String[] listData = { "one", "two", "three", "four", "five", "six", "seven" };
    String[] columnNames = { "French", "Spanish", "Italian" };
    list = new JList(listData);

    listSelectionModel = list.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    JScrollPane listPane = new JScrollPane(list);

    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);/*from   w  w  w  .  ja v a2s.  c  om*/
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    // Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    listContainer.setBorder(BorderFactory.createTitledBorder("List"));
    listContainer.add(listPane);

    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    // topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(100, 50));
    topHalf.setPreferredSize(new Dimension(100, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    // XXX: next line needed if bottomHalf is a scroll pane:
    // bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 135));
    splitPane.add(bottomHalf);
}

From source file:events.TableListSelectionDemo.java

public TableListSelectionDemo() {
    super(new BorderLayout());

    String[] columnNames = { "French", "Spanish", "Italian" };
    String[][] tableData = { { "un", "uno", "uno" }, { "deux", "dos", "due" }, { "trois", "tres", "tre" },
            { "quatre", "cuatro", "quattro" }, { "cinq", "cinco", "cinque" }, { "six", "seis", "sei" },
            { "sept", "siete", "sette" } };

    table = new JTable(tableData, columnNames);
    listSelectionModel = table.getSelectionModel();
    listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
    table.setSelectionModel(listSelectionModel);
    JScrollPane tablePane = new JScrollPane(table);

    //Build control area (use default FlowLayout).
    JPanel controlPane = new JPanel();
    String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" };

    final JComboBox comboBox = new JComboBox(modes);
    comboBox.setSelectedIndex(2);//from ww w.j av a 2  s . co m
    comboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String newMode = (String) comboBox.getSelectedItem();
            if (newMode.equals("SINGLE_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) {
                listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            } else {
                listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            }
            output.append("----------" + "Mode: " + newMode + "----------" + newline);
        }
    });
    controlPane.add(new JLabel("Selection mode:"));
    controlPane.add(comboBox);

    //Build output area.
    output = new JTextArea(1, 10);
    output.setEditable(false);
    JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    //Do the layout.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(splitPane, BorderLayout.CENTER);

    JPanel topHalf = new JPanel();
    topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS));
    JPanel listContainer = new JPanel(new GridLayout(1, 1));
    JPanel tableContainer = new JPanel(new GridLayout(1, 1));
    tableContainer.setBorder(BorderFactory.createTitledBorder("Table"));
    tableContainer.add(tablePane);
    tablePane.setPreferredSize(new Dimension(420, 130));
    topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
    topHalf.add(listContainer);
    topHalf.add(tableContainer);

    topHalf.setMinimumSize(new Dimension(250, 50));
    topHalf.setPreferredSize(new Dimension(200, 110));
    splitPane.add(topHalf);

    JPanel bottomHalf = new JPanel(new BorderLayout());
    bottomHalf.add(controlPane, BorderLayout.PAGE_START);
    bottomHalf.add(outputPane, BorderLayout.CENTER);
    //XXX: next line needed if bottomHalf is a scroll pane:
    //bottomHalf.setMinimumSize(new Dimension(400, 50));
    bottomHalf.setPreferredSize(new Dimension(450, 110));
    splitPane.add(bottomHalf);
}