Example usage for javax.swing JPanel setLayout

List of usage examples for javax.swing JPanel setLayout

Introduction

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

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:fungus.PeerRatioChartFrame.java

public PeerRatioChartFrame(String prefix) {
    simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES);
    this.setTitle("MycoNet Statistics Chart");
    graph = JungGraphObserver.getGraph();

    //data.add(-1,0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.setAutoWidth(false);//from  w  ww .  j  a v  a2  s  .co m
    dataset.setIntervalWidth(simulationCycles);

    //averageUtilizationData = new XYSeries("Average Utilization");
    //dataset.addSeries(averageUtilizationData);
    //averageStableUtilizationData = new XYSeries("Avg Stable Util");
    //dataset.addSeries(averageStableUtilizationData);
    bulwarkRatioData = new XYSeries("Bulwark Ratio");
    dataset.addSeries(bulwarkRatioData);
    biomassRatioData = new XYSeries("Biomass Ratio");
    dataset.addSeries(biomassRatioData);
    hyphaRatioData = new XYSeries("Hypha Ratio");
    dataset.addSeries(hyphaRatioData);
    // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio");
    // dataset.addSeries(stableHyphaRatioData);

    //XYSeriesCollection dataset;

    JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart);

    XYPlot xyplot = peerRatioChart.getXYPlot();

    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(0, 1);

    //chart.setBackgroundPaint(Color.white);
    //XYPlot plot = chart.getXYPlot();

    //        BufferedImage chartImage = chart.createBufferedImage(500,300);
    //        chartLabel = new JLabel();
    //chartLabel.setIcon(new ImageIcon(chartImage));

    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(1, 1));
    //chartPane.setPreferredSize(new java.awt.Dimension(500, 300));
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    ////contentPane.add(labelPane,BorderLayout.PAGE_START);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(peerRatioChartPanel, BorderLayout.CENTER);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    ////contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //data = node.getHyphaData();
    //link = node.getHyphaLink();
    //mycocast = node.getMycoCast();

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    //chartPanel.add(chartLabel);

    /*JButton updateButton = new JButton("Refresh");
      ActionListener updater = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      refreshData();
      }
      };
      updateButton.addActionListener(updater);
            
      JButton closeButton = new JButton("Close");
      ActionListener closer = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      closeFrame();
      }
      };
      closeButton.addActionListener(closer);
            
      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(updateButton);
      buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
      buttonPane.add(closeButton);
      refreshData();
    */

    //JungGraphObserver.addChangeListener(this);

    this.pack();
    this.setVisible(true);
}

From source file:com.mirth.connect.client.ui.alert.DefaultAlertEditPanel.java

private void initComponents() {
    setBackground(UIConstants.BACKGROUND_COLOR);
    setLayout(new MigLayout("insets 10", "grow", "[][grow][grow]"));

    nameLabel = new JLabel("Alert Name: ");
    nameTextField = new MirthTextField();

    nameTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent evt) {
            parent.setPanelName("Edit Alert - " + nameTextField.getText());
        }/*  w  w w . j  av a 2s  . c  o m*/
    });

    enabledCheckBox = new MirthCheckBox("Enabled");
    enabledCheckBox.setBackground(UIConstants.BACKGROUND_COLOR);

    JPanel headerPanel = new JPanel();
    headerPanel.setBackground(UIConstants.BACKGROUND_COLOR);
    headerPanel.setLayout(new MigLayout("insets 0"));
    headerPanel.add(nameLabel, "");
    headerPanel.add(nameTextField, "width 500");
    headerPanel.add(enabledCheckBox, "wrap");

    alertTriggerPane = new DefaultAlertTriggerPane();

    alertChannelPane = new AlertChannelPane();

    alertActionPane = new AlertActionPane();

    add(headerPanel, "grow, span");
    add(alertTriggerPane, "grow, sg 1, height 100");
    add(alertChannelPane, "grow, sg 1, height 100, wrap");
    add(alertActionPane, "grow, sgy 1, width 100, height 100, span");
}

From source file:DecimalFormatDemo.java

public DecimalFormatDemo() {

    availableLocales = new LocaleGroup();
    inputFormatter = NumberFormat.getNumberInstance();

    String[] patternExamples = { "##.##", "###,###.##", "##,##,##.##", "#", "000,000.0000", "##.0000",
            "'hello'###.##" };

    currentPattern = patternExamples[0];

    // Set up the UI for entering a number.
    JLabel numberLabel = new JLabel("Enter the number to format:");
    numberLabel.setAlignmentX(Component.LEFT_ALIGNMENT);

    JTextField numberField = new JTextField();
    numberField.setEditable(true);/*from   w  w  w  .j a v  a2  s . com*/
    numberField.setAlignmentX(Component.LEFT_ALIGNMENT);
    NumberListener numberListener = new NumberListener();
    numberField.addActionListener(numberListener);

    // Set up the UI for selecting a pattern.
    JLabel patternLabel1 = new JLabel("Enter the pattern string or");
    JLabel patternLabel2 = new JLabel("select one from the list:");
    patternLabel1.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternLabel2.setAlignmentX(Component.LEFT_ALIGNMENT);

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setSelectedIndex(0);
    patternList.setEditable(true);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    PatternListener patternListener = new PatternListener();
    patternList.addActionListener(patternListener);

    // Set up the UI for selecting a locale.
    JLabel localeLabel = new JLabel("Select a Locale from the list:");
    localeLabel.setAlignmentX(Component.LEFT_ALIGNMENT);

    JComboBox localeList = new JComboBox(availableLocales.getStrings());
    localeList.setSelectedIndex(0);
    localeList.setAlignmentX(Component.LEFT_ALIGNMENT);
    LocaleListener localeListener = new LocaleListener();
    localeList.addActionListener(localeListener);

    // Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Result", JLabel.LEFT);
    resultLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setAlignmentX(Component.LEFT_ALIGNMENT);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    // Lay out everything
    JPanel numberPanel = new JPanel();
    numberPanel.setLayout(new GridLayout(0, 1));
    numberPanel.add(numberLabel);
    numberPanel.add(numberField);

    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.Y_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternPanel.add(patternList);

    JPanel localePanel = new JPanel();
    localePanel.setLayout(new BoxLayout(localePanel, BoxLayout.Y_AXIS));
    localePanel.add(localeLabel);
    localePanel.add(localeList);

    JPanel resultPanel = new JPanel();
    resultPanel.setLayout(new GridLayout(0, 1));
    resultPanel.add(resultLabel);
    resultPanel.add(result);

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    patternPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    numberPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    localePanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    resultPanel.setAlignmentX(Component.CENTER_ALIGNMENT);

    add(numberPanel);
    add(Box.createVerticalStrut(10));
    add(patternPanel);
    add(Box.createVerticalStrut(10));
    add(localePanel);
    add(Box.createVerticalStrut(10));
    add(resultPanel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    reformat();
    numberField.setText(result.getText());

}

From source file:SortedTableModel.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    Component text;/*from   www.ja v  a  2  s.com*/
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    if (textRenderer != null) {
        text = textRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    } else {
        text = new JLabel((String) value, JLabel.CENTER);
        LookAndFeel.installColorsAndFont((JComponent) text, "TableHeader.background", "TableHeader.foreground",
                "TableHeader.font");
    }
    panel.add(text, BorderLayout.CENTER);

    if (column == sortColumn) {
        BasicArrowButton bab = new BasicArrowButton(
                (sortAscending ? SwingConstants.NORTH : SwingConstants.SOUTH));
        panel.add(bab, BorderLayout.WEST);
    }
    LookAndFeel.installBorder(panel, "TableHeader.cellBorder");
    return panel;
}

From source file:kenh.xscript.elements.Debug.java

private void initial(Container c) {
    c.setLayout(new BorderLayout());

    // Add variable list

    DefaultListModel<String> model = new DefaultListModel();

    if (this.getEnvironment() != null) {
        java.util.Set<String> keys = this.getEnvironment().getVariables().keySet();
        for (String key : keys) {
            model.addElement(key);//w ww.  j ava 2  s  .  co m
        }
    } else {
        for (int i = 1; i < 10; i++) {
            model.addElement("Variable " + i);
        }
        model.addElement("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }

    JList list = new JList(model);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane listPane = new JScrollPane();
    listPane.setViewportView(list);
    listPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    c.add(listPane, BorderLayout.EAST);

    list.setPreferredSize(new Dimension(150, list.getPreferredSize().height));

    // 

    JTextField quote = new JTextField();
    quote.requestFocus();

    //JButton button = new JButton(">>");

    JPanel quotePanel = new JPanel();
    quotePanel.setLayout(new BorderLayout());
    quotePanel.add(quote, BorderLayout.CENTER);
    //quotePanel.add(button, BorderLayout.EAST);

    JTextArea result = new JTextArea();
    result.setEditable(false);

    JScrollPane resultPane = new JScrollPane();
    resultPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    resultPane.setViewportView(result);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(quotePanel, BorderLayout.NORTH);
    panel.add(resultPane, BorderLayout.CENTER);

    c.add(panel, BorderLayout.CENTER);

    list.addListSelectionListener(this);
    //button.addActionListener(this);
    quote.addKeyListener(this);

    this.result = result;
}

From source file:InternalFrameEventDemo.java

protected void createDisplayWindow() {
    JButton b1 = new JButton("Show internal frame");
    b1.setActionCommand(SHOW);//from  w w  w .  ja  va  2 s .  c o m
    b1.addActionListener(this);

    JButton b2 = new JButton("Clear event info");
    b2.setActionCommand(CLEAR);
    b2.addActionListener(this);

    display = new JTextArea(3, 30);
    display.setEditable(false);
    JScrollPane textScroller = new JScrollPane(display);
    //Have to supply a preferred size, or else the scroll
    //area will try to stay as large as the text area.
    textScroller.setPreferredSize(new Dimension(200, 75));
    textScroller.setMinimumSize(new Dimension(10, 10));

    displayWindow = new JInternalFrame("Event Watcher", true, //resizable
            false, //not closable
            false, //not maximizable
            true); //iconifiable
    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    b1.setAlignmentX(CENTER_ALIGNMENT);
    contentPane.add(b1);
    contentPane.add(Box.createRigidArea(new Dimension(0, 5)));
    contentPane.add(textScroller);
    contentPane.add(Box.createRigidArea(new Dimension(0, 5)));
    b2.setAlignmentX(CENTER_ALIGNMENT);
    contentPane.add(b2);

    displayWindow.setContentPane(contentPane);
    displayWindow.pack();
    displayWindow.setVisible(true);
}

From source file:genlib.output.gui.Graph2D.java

/**
 * open a window with one or more plot-collections
 *
 * @param rows count of rows//  www . ja  v  a2s  .  c  o m
 * @param cols count of columns
 * @param gap size of gaps between Plots (in pixel)
 * @param percentSizeOfScreen the size of the complete window in per-cent of the windows
 * @param plots the plot-collections, can have null's inside,then there is empty space on the window
 * @return the window-object
 * @throws IllegalArgumentException if rows or cols lower than 1, gap lower than 0, percentSizeOfScreen lower than 0.001 or higher than 1 or number of plots not the same as rows*cols
 */
public static Graph2D open(int rows, int cols, int gap, double percentSizeOfScreen, PlotCollection... plots) {
    if (rows <= 0)
        throw new IllegalArgumentException("invalid rows-count: '" + rows + "'.");
    if (cols <= 0)
        throw new IllegalArgumentException("invalid cols-count: '" + cols + "'.");
    if (gap < 0)
        throw new IllegalArgumentException("invalid gap: '" + gap + "'.");
    if (percentSizeOfScreen < 0.001 || percentSizeOfScreen > 1)
        throw new IllegalArgumentException("invalid percentSizeOfScreen: '" + percentSizeOfScreen + "'.");
    if (plots == null || plots.length != rows * cols)
        throw new IllegalArgumentException("length of plots is not rows*cols.");

    //the window-title is a concatenation of all plots
    //but first, we have to ignore all null-plots
    String windowTitle = "";
    List<PlotCollection> plotsNotNull = new ArrayList();
    for (PlotCollection plot : plots)
        if (plot != null)
            plotsNotNull.add(plot);

    if (plotsNotNull.isEmpty())
        windowTitle = "no plots";
    else
        for (int i = 0; i < plotsNotNull.size(); i++)
            windowTitle += (i > 0 ? ", " : "") + plotsNotNull.get(i).title;

    //create the window
    Graph2D ret = new Graph2D(windowTitle);

    //and create the row-col-layout
    JPanel grid = new JPanel();
    grid.setLayout(new GridLayout(rows, cols, gap, gap));
    for (PlotCollection plot : plots)
        if (plot == null)
            grid.add(new JLabel(""));
        else
            grid.add(plot.getGUIElement());

    //some other attributes of the window
    grid.setBackground(Color.BLACK);
    ret.setContentPane(grid);
    ret.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    ret.setSize(new Dimension((int) (screenSize.getWidth() * percentSizeOfScreen),
            (int) (screenSize.getHeight() * percentSizeOfScreen)));
    RefineryUtilities.centerFrameOnScreen(ret);
    ret.setVisible(true);

    return ret;
}

From source file:net.sf.maltcms.chromaui.foldChangeViewer.ui.FoldChangeViewTopComponent.java

public void initialize(final IChromAUIProject project,
        final ADataset1D<StatisticsContainer, FoldChangeElement> ds) {
    if (initialized.compareAndSet(false, true)) {
        final ProgressHandle handle = ProgressHandleFactory.createHandle("Loading chart");
        final JComponent progressComponent = ProgressHandleFactory.createProgressComponent(handle);
        final JPanel box = new JPanel();
        box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
        box.add(Box.createHorizontalGlue());
        box.add(progressComponent);//from  w w  w .  j a  v  a 2  s.  co  m
        box.add(Box.createHorizontalGlue());
        add(box, BorderLayout.CENTER);
        AProgressAwareRunnable runnable = new AProgressAwareRunnable() {
            @Override
            public void run() {
                try {
                    handle.start();
                    handle.progress("Initializing Overlays...");
                    if (project != null) {
                        ic.add(project);
                    }
                    dataset = ds;
                    annotations = new ArrayList<XYAnnotation>(0);
                    final DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
                    ic.add(ds);
                    for (int i = 0; i < ds.getSeriesCount(); i++) {
                        ic.add(ds.getSource(i));
                    }
                    handle.progress("Initializing Settings and Properties...");
                    ic.add(new Properties());
                    sp = new SettingsPanel();
                    ic.add(sp);
                    handle.progress("Creating panel...");
                    jp = new FoldChangeViewPanel(ic, getLookup(), ds);
                    ic.add(jp);
                    ic.add(this);
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            //EDT stuff
                            setDisplayName("Fold change view of " + ds.getDisplayName());
                            setToolTipText(ds.getDescription());
                            remove(box);
                            add(jp, BorderLayout.CENTER);
                            load();
                        }
                    });
                } finally {
                    handle.finish();
                }
            }
        };
        runnable.setProgressHandle(handle);
        AProgressAwareRunnable.createAndRun("Creating chart", runnable);
    }
}

From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java

private JPanel createDecompositionPanel(String title, double[][] mdsValues) {
    JFreeChart chart = ChartFactory.createScatterPlot(title, null, null, new MdsXYDataset(mdsValues),
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override//from  w ww .j  a  v a  2 s . c o  m
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "item #" + (item + 1);
        }
    });

    JPanel mdsPanel = new JPanel(new BorderLayout(0, 10));
    mdsPanel.add(new ChartPanel(chart), BorderLayout.CENTER);
    dimensionsCombo = new JComboBox(new Integer[] { 2, 3 });
    JButton exportButton = new JButton(Translation.INSTANCE.get("s4.bu.exportDecomposition"));
    exportButton.addActionListener(this);
    JPanel mdsInputPanel = new JPanel();
    mdsInputPanel.setLayout(new BoxLayout(mdsInputPanel, BoxLayout.LINE_AXIS));
    mdsInputPanel.add(Box.createHorizontalGlue());
    mdsInputPanel.add(Box.createHorizontalGlue());
    mdsInputPanel.add(new JLabel(Translation.INSTANCE.get("s4.lb.dimension")));
    mdsInputPanel.add(Box.createHorizontalStrut(10));
    mdsInputPanel.add(dimensionsCombo);
    mdsInputPanel.add(Box.createHorizontalStrut(10));
    mdsInputPanel.add(exportButton);
    mdsPanel.add(mdsInputPanel, BorderLayout.SOUTH);

    return mdsPanel;
}

From source file:com.orthancserver.OrthancConfigurationDialog.java

public OrthancConfigurationDialog() {
    final JPanel contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(20, 5, 5, 5));
    contentPanel.setLayout(new GridLayout2(0, 2, 20, 5));

    JLabel label = new JLabel("Name:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);//from   ww  w  .ja  v a  2s  .  com
    contentPanel.add(name_);

    label = new JLabel("URL:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);
    contentPanel.add(url_);

    label = new JLabel("Username:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);
    contentPanel.add(username_);

    label = new JLabel("Password:");
    label.setHorizontalAlignment(JLabel.RIGHT);
    contentPanel.add(label);
    contentPanel.add(password_);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(contentPanel, BorderLayout.NORTH);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    getContentPane().add(buttonPane, BorderLayout.SOUTH);
    {
        {
            JButton test = new JButton("Test connection");
            test.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    OrthancConnection orthanc = CreateConnection();
                    try {
                        JSONObject system = (JSONObject) orthanc.ReadJson("system");
                        JOptionPane.showMessageDialog(null,
                                "Successfully connected to this Orthanc server " + "(version: "
                                        + (String) system.get("Version") + ")!",
                                "Success", JOptionPane.INFORMATION_MESSAGE);
                    } catch (IOException e) {
                        JOptionPane.showMessageDialog(null, "Cannot connect to this Orthanc server!", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    }
                }
            });
            buttonPane.add(test);
        }
        {
            JButton okButton = new JButton("Add");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    isSuccess_ = true;
                    setVisible(false);
                }
            });
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    setVisible(false);
                }
            });
            buttonPane.add(cancelButton);
        }
    }

    setUndecorated(false);
    setSize(500, 500);
    setTitle("Add new server");
    setModal(true);
}