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:ColorApp.java

public ColorApp() {
    super();//from w  w w  .j  av  a  2  s .  c o  m
    Container container = getContentPane();

    displayPanel = new DisplayPanel();
    container.add(displayPanel);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(3, 2));
    panel.setBorder(new TitledBorder("Click a Button to Perform the Associated Operation and Reset..."));

    brightenButton = new JButton("Brightness >>");
    brightenButton.addActionListener(new ButtonListener());
    darkenButton = new JButton("Darkness >>");
    darkenButton.addActionListener(new ButtonListener());
    contrastIncButton = new JButton("Contrast >>");
    contrastIncButton.addActionListener(new ButtonListener());
    contrastDecButton = new JButton("Contrast <<");
    contrastDecButton.addActionListener(new ButtonListener());
    reverseButton = new JButton("Negative");
    reverseButton.addActionListener(new ButtonListener());
    resetButton = new JButton("Reset");
    resetButton.addActionListener(new ButtonListener());

    panel.add(brightenButton);
    panel.add(darkenButton);
    panel.add(contrastIncButton);
    panel.add(contrastDecButton);
    panel.add(reverseButton);
    panel.add(resetButton);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowEventHandler());
    setSize(displayPanel.getWidth(), displayPanel.getHeight() + 25);
    show();
}

From source file:com.opendoorlogistics.components.reports.ReporterPanel.java

public ReporterPanel(final ComponentConfigurationEditorAPI api, final ReporterConfig config) {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    // setAlignmentX(LEFT_ALIGNMENT);

    // add config panel
    ReporterConfigPanel configPanel = new ReporterConfigPanel(config);
    configPanel.setBorder(createBorder("Export and processing options"));
    add(configPanel);/*from   w w w .j  ava2 s. com*/

    // add gap
    add(Box.createRigidArea(new Dimension(1, 10)));

    // add tools panel
    JPanel toolContainer = new JPanel();
    toolContainer.setLayout(new BorderLayout());
    toolContainer.setBorder(createBorder("Tools"));

    add(toolContainer);

    JPanel tools = new JPanel();
    toolContainer.add(tools, BorderLayout.NORTH);
    toolContainer.setMaximumSize(new Dimension(Integer.MAX_VALUE, api.isInstruction() ? 120 : 80));
    // tools.setLayout(new BoxLayout(tools, BoxLayout.X_AXIS));
    tools.setLayout(new GridLayout(api == null || api.isInstruction() ? 2 : 1, 3));
    JButton compileButton = new JButton("Compile .jrxml file");
    compileButton.setToolTipText("Compile a JasperReports .jrxml file");
    compileButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            File file = ReporterTools.chooseJRXMLFile(api.getComponentPreferences(), LAST_JRXML_TO_COMPILE,
                    ReporterPanel.this);
            if (file == null) {
                return;
            }

            final ExecutionReport report = api.getApi().uiFactory().createExecutionReport();
            try {
                JasperDesign design = JRXmlLoader.load(file);
                if (design == null) {
                    throw new RuntimeException("File to load jrxml: " + file.getAbsolutePath());
                }

                String filename = FilenameUtils.removeExtension(file.getAbsolutePath()) + ".jasper";
                JasperCompileManager.compileReportToFile(design, filename);
            } catch (Throwable e2) {
                report.setFailed(e2);
                report.setFailed("Failed to compile file " + file.getAbsolutePath());
            } finally {
                if (report.isFailed()) {
                    Window window = SwingUtilities.getWindowAncestor(ReporterPanel.this);
                    api.getApi().uiFactory()
                            .createExecutionReportDialog(
                                    JFrame.class.isInstance(window) ? (JFrame) window : null,
                                    "Compiling jrxml file", report, true)
                            .setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(ReporterPanel.this,
                            "Compiled jxrml successfully: " + file.getAbsolutePath());
                }
            }
        }
    });
    tools.add(compileButton);

    for (final OrientationEnum orientation : new OrientationEnum[] { OrientationEnum.LANDSCAPE,
            OrientationEnum.PORTRAIT }) {
        // create export button
        JButton button = new JButton("Export " + orientation.getName().toLowerCase() + " template");
        button.setToolTipText(
                "Export template (editable .jrxml and compiled .jasper) based on the input tables ("
                        + orientation.getName().toLowerCase() + ")");
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                ReporterTools.exportReportTemplate(api, config, orientation, ReporterPanel.this);
            }
        });
        tools.add(button);

        // create view button
        if (api.isInstruction()) {
            final String title = "View basic " + orientation.getName().toLowerCase() + " report";
            button = new JButton(title);
            button.setToolTipText("View basic report based on the input tables ("
                    + orientation.getName().toLowerCase() + ")");
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (api != null) {
                        api.executeInPlace(title,
                                orientation == OrientationEnum.LANDSCAPE
                                        ? ReporterComponent.VIEW_BASIC_LANDSCAPE
                                        : ReporterComponent.VIEW_BASIC_PORTRAIT);
                    }
                }
            });
            tools.add(button);
        }
    }

}

From source file:ch.epfl.leb.sass.ijplugin.SimulatorStatusFrame.java

/** 
 * Creates a new status frame./* www . j  a v a 2s .  c o  m*/
 * 
 * @param groundTruthYLabel The y-axis label for the ground truth signal.
 * @param analyzerYLabel The units output by the analyzer.
 * @param setpointYLabel The units of the controller setpoint.
 * @param outputYLabel The units output by the controller.
 */
public SimulatorStatusFrame(String groundTruthYLabel, String analyzerYLabel, String setpointYLabel,
        String outputYLabel) {
    String seriesLabel = "";
    String yLabel = "";
    CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new NumberAxis("Simulation Outputs"));
    Font yLabelFont = new Font("Dialog", Font.PLAIN, 10);
    datasets = new XYSeriesCollection[4];
    for (int i = 0; i < SUBPLOT_COUNT; i++) {
        switch (i) {
        case 0:
            seriesLabel = "True density";
            yLabel = groundTruthYLabel;
            break;
        case 1:
            seriesLabel = "Analyzer output";
            yLabel = analyzerYLabel;
            break;
        case 2:
            seriesLabel = "Setpoint";
            yLabel = setpointYLabel;
            break;
        case 3:
            seriesLabel = "Controller output";
            yLabel = outputYLabel;
            break;
        }

        XYSeries timeseries = new XYSeries(seriesLabel);
        datasets[i] = new XYSeriesCollection(timeseries);

        NumberAxis numberaxis = new NumberAxis(yLabel);
        numberaxis.setAutoRangeIncludesZero(false);
        numberaxis.setNumberFormatOverride(new DecimalFormat("###0.00"));
        XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer());
        xyplot.setBackgroundPaint(Color.lightGray);
        xyplot.setDomainGridlinePaint(Color.white);
        xyplot.setRangeGridlinePaint(Color.white);
        xyplot.getRangeAxis().setLabelFont(yLabelFont);
        combineddomainxyplot.add(xyplot);
    }

    JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, combineddomainxyplot, true);
    jfreechart.setBorderPaint(Color.black);
    jfreechart.setBorderVisible(true);
    jfreechart.setBackgroundPaint(Color.white);
    combineddomainxyplot.setBackgroundPaint(Color.lightGray);
    combineddomainxyplot.setDomainGridlinePaint(Color.white);
    combineddomainxyplot.setRangeGridlinePaint(Color.white);
    ValueAxis valueaxis = combineddomainxyplot.getDomainAxis();
    valueaxis.setAutoRange(true);
    // Number of frames to display
    valueaxis.setFixedAutoRange(2000D);

    ChartPanel chartpanel = new ChartPanel(jfreechart);

    chartpanel.setPreferredSize(new Dimension(800, 500));
    chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    chartpanel.setVisible(true);

    JPanel jPanel = new JPanel();
    jPanel.setLayout(new BorderLayout());
    jPanel.add(chartpanel, BorderLayout.NORTH);

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    add(jPanel);
    pack();
    setVisible(true);

}

From source file:com.hazelcast.simulator.visualiser.ui.Chart.java

public Chart(Model model, AccuracyRadioButtons accuracyRadioButtons,
        AutoScaleRadioButtons autoScaleRadioButtons, ProbesCheckboxes probesCheckboxes) {
    this.model = model;
    this.accuracyRadioButtons = accuracyRadioButtons;
    this.autoScaleRadioButtons = autoScaleRadioButtons;
    this.probesCheckboxes = probesCheckboxes;

    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    setLayout(new BorderLayout());

    initSliders();//from w  w  w  .  j  av  a  2 s . com

    JPanel horizontalSlidersPanel = new JPanel();
    horizontalSlidersPanel.setLayout(new BoxLayout(horizontalSlidersPanel, BoxLayout.Y_AXIS));
    horizontalSlidersPanel.add(mainHorizontalSlider);
    horizontalSlidersPanel.add(fineHorizontalSlider);

    JFreeChart chart = ChartFactory.createHistogram("Latency Distribution", "Latency (s)", "Operations", null,
            PlotOrientation.VERTICAL, true, true, true);

    plot = chart.getXYPlot();
    plot.setForegroundAlpha(ALPHA);

    ChartPanel chartPanel = new ChartPanel(null);
    chartPanel.setChart(chart);

    add(horizontalSlidersPanel, BorderLayout.SOUTH);
    add(verticalSlider, BorderLayout.EAST);
    add(chartPanel, BorderLayout.CENTER);

    initSliderChangeListener();
}

From source file:ChooseDropActionDemo.java

public ChooseDropActionDemo() {
    super("ChooseDropActionDemo");

    for (int i = 15; i >= 0; i--) {
        from.add(0, "Source item " + i);
    }/* w ww  .  j  a  v  a2 s  .  c  o  m*/

    for (int i = 2; i >= 0; i--) {
        copy.add(0, "Target item " + i);
        move.add(0, "Target item " + i);
    }

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    dragFrom = new JList(from);
    dragFrom.setTransferHandler(new FromTransferHandler());
    dragFrom.setPrototypeCellValue("List Item WWWWWW");
    dragFrom.setDragEnabled(true);
    dragFrom.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JLabel label = new JLabel("Drag from here:");
    label.setAlignmentX(0f);
    p.add(label);
    JScrollPane sp = new JScrollPane(dragFrom);
    sp.setAlignmentX(0f);
    p.add(sp);
    add(p, BorderLayout.WEST);

    JList moveTo = new JList(move);
    moveTo.setTransferHandler(new ToTransferHandler(TransferHandler.COPY));
    moveTo.setDropMode(DropMode.INSERT);
    JList copyTo = new JList(copy);
    copyTo.setTransferHandler(new ToTransferHandler(TransferHandler.MOVE));
    copyTo.setDropMode(DropMode.INSERT);

    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    label = new JLabel("Drop to COPY to here:");
    ;
    label.setAlignmentX(0f);
    p.add(label);
    sp = new JScrollPane(moveTo);
    sp.setAlignmentX(0f);
    p.add(sp);
    label = new JLabel("Drop to MOVE to here:");
    label.setAlignmentX(0f);
    p.add(label);
    sp = new JScrollPane(copyTo);
    sp.setAlignmentX(0f);
    p.add(sp);
    p.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
    add(p, BorderLayout.CENTER);

    ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

    getContentPane().setPreferredSize(new Dimension(320, 315));
}

From source file:com.devoteam.srit.xmlloader.core.report.derived.StatCount.java

@Override
public JPanel generateShortRTStats() {
    JPanel panel = new JPanel();
    panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
    panel.add(new JLabel(Utils.formatdouble(this.counter.globalDataset.getValue())));
    panel.setToolTipText(generateRTStatsToolTip());

    addMouseListenerForGraph(panel);//from w  ww .  j av  a 2  s  . c o m

    return panel;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploaderThumbnailerTester_2.java

private Component createImagePanel(CropData cropData) {
    RenderedOp image = createCroppedImage(cropData);

    Set<String> blackSides = checkBlackEdges(image);
    if (!blackSides.isEmpty()) {
        log.warn("edges  at " + cropData + ", " + blackSides);
    }/*from w ww .  ja v  a  2s .c o m*/

    String legend = "left=" + cropData.left + ", top=" + cropData.top + ", size=" + cropData.size;
    Label l = new Label();
    l.setAlignment(Label.CENTER);
    if (!blackSides.isEmpty()) {
        l.setBackground(new Color(0xFFDDDD));
        legend += " " + blackSides;
    }
    l.setText(legend);

    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add("South", l);
    p.add("Center", new ImageCanvas(image));
    p.setBackground(new Color(0xFFFFFF));
    p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    return p;
}

From source file:Interface.ResultadoJanela.java

public ResultadoJanela(List<Resultado> tar, List<Resultado> jac, List<Resultado> och, List<Resultado> sbi) {
    //  super("Resultado");
    CategoryDataset dataset;// ww w  . jav  a  2 s . c o m

    //---------------------gerando resultados tarantula-------------------------------------
    dataset = gerarDataset(tar, jac, och, sbi);
    JFreeChart chart = gerarGrafico(dataset);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setDomainZoomable(true);

    JLabel lAjuda = new JLabel("Ajuda", JLabel.RIGHT);
    lAjuda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icone_informacao.gif"))); // NOI18N
    lAjuda.setPreferredSize(new Dimension(50, 50));
    lAjuda.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            lAjudaMouseClicked(evt);
        }
    });

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(lAjuda, BorderLayout.BEFORE_FIRST_LINE);
    panel.add(chartPanel, BorderLayout.LINE_START);
    JLabel lTabela = new JLabel("Tabela de Resultados", JLabel.CENTER);
    panel.add(lTabela, BorderLayout.SOUTH);

    JTable table = new JTable(criarValores(tar, jac, och, sbi), criarColunas());

    // Adiciona o JTable dentro do painel
    JScrollPane scrollPane = new JScrollPane(table);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    panel.add(scrollPane, BorderLayout.SOUTH);

    JFrame frame = new JFrame();
    frame.setTitle("JLoc - Resultado");
    frame.setVisible(true);
    frame.add(panel);

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

From source file:de.codesourcery.eve.skills.ui.utils.PersistentDialog.java

public PersistentDialog(String id, Icon icon, String title, String label, PersistenceType type, Kind kind) {
    super(null, title, ModalityType.APPLICATION_MODAL);

    if (kind == null) {
        throw new IllegalArgumentException("kind cannot be NULL");
    }//w  w  w .  j a  va  2 s  .  c  om

    if (StringUtils.isBlank(id)) {
        throw new IllegalArgumentException("id cannot be blank.");
    }

    if (type == null) {
        throw new IllegalArgumentException("type cannot be NULL");
    }

    if (StringUtils.isBlank(label)) {
        throw new IllegalArgumentException("label cannot be blank.");
    }

    this.id = id;
    this.type = type;

    // configure checkbox
    isDialogEnabled = new JCheckBox("Always show this dialog ?", true);
    isDialogEnabled.setHorizontalTextPosition(SwingConstants.RIGHT);

    // add panel
    final JPanel content = new JPanel();
    content.setLayout(new GridBagLayout());

    content.add(new JLabel(icon),
            new ConstraintsBuilder().x(0).y(0).anchorWest().noResizing().useRelativeWidth().end());
    content.add(new JLabel(label),
            new ConstraintsBuilder().x(1).y(0).anchorWest().resizeBoth().useRemainingWidth().end());
    content.add(isDialogEnabled, new ConstraintsBuilder().x(0).y(1).width(2).anchorWest().noResizing().end());

    final JPanel buttonPanel = new JPanel();
    buttonPanel.add(okButton);

    final ActionListener listener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == cancelButton) {
                wasCancelled = true;
            }
            dispose();
        }
    };

    okButton.addActionListener(listener);

    if (kind == Kind.CANCEL) {
        buttonPanel.add(cancelButton);
        cancelButton.addActionListener(listener);
    }

    content.add(buttonPanel, new ConstraintsBuilder().x(0).y(2).useRemainingSpace().end());

    getContentPane().add(content);

    pack();

    setLocationRelativeTo(null);

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            wasCancelled = true;
            dispose();
        }
    });
}

From source file:edu.cornell.mannlib.vitro.webapp.imageprocessor.jai.JaiImageProcessorTester2.java

private Component createImagePanel(CropData cropData) {
    RenderedOp image = createCroppedImage(cropData);

    Set<String> blackSides = checkBlackEdges(image);
    if (!blackSides.isEmpty()) {
        log.warn("edges  at " + cropData + ", " + blackSides);
    }/*from   www  .  jav a  2  s .co  m*/

    String legend = "left=" + cropData.left + ", top=" + cropData.top + ", size=" + cropData.size;
    Label l = new Label();
    l.setAlignment(Label.CENTER);
    if (!blackSides.isEmpty()) {
        l.setBackground(new Color(0xFFDDDD));
        legend += " " + blackSides;
    }
    l.setText(legend);

    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add("South", l);
    p.add("Center", new javax.media.jai.widget.ImageCanvas(image));
    p.setBackground(new Color(0xFFFFFF));
    p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    return p;
}