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

public SimpleBufferedImageDemo() {
    super();//from  www. ja  va 2s  . c  o  m
    Container container = getContentPane();

    canvas = new DisplayCanvas();
    container.add(canvas);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 2));
    panel.setBorder(new TitledBorder("Select an Option and Display Image..."));

    buffButton = new JRadioButton("Buffered");
    buffButton.addActionListener(new ButtonListener());
    nonBuffButton = new JRadioButton("Non-Buffered", true);
    nonBuffButton.addActionListener(new ButtonListener());
    ButtonGroup group = new ButtonGroup();
    group.add(buffButton);
    group.add(nonBuffButton);

    displayButton = new JButton("Display");
    displayButton.addActionListener(new ButtonListener());
    clearButton = new JButton("Clear");
    clearButton.addActionListener(new ButtonListener());

    panel.add(nonBuffButton);
    panel.add(buffButton);
    panel.add(displayButton);
    panel.add(clearButton);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowEventHandler());
    pack();
    setVisible(true);
}

From source file:probe.com.model.util.vaadintoimageutil.HeatmapSwingComponent.java

public String generateHeatmap(String[] rows, String[] columns, String[][] data) {

    JPanel heatmapPanelLayout = new JPanel();
    heatmapPanelLayout.setLayout(null);
    heatmapPanelLayout.setVisible(true);
    heatmapPanelLayout.setBorder(new LineBorder(Color.BLACK));
    int width = (columns.length + 1) * 50;
    int height = (rows.length + 1) * 50;
    heatmapPanelLayout.setSize(width, height);
    JPanel cornerCell = initCell("#ffffff", 0, 0);
    int x = 50;//from   w w  w  . jav a 2  s. co  m
    int y = 0;
    heatmapPanelLayout.add(cornerCell);

    for (String headerCell : columns) {
        JPanel cell = initCell(headerCell, x, y);
        x += 50;
        heatmapPanelLayout.add(cell);

    }
    y = 50;
    for (String headerCell : rows) {
        JPanel cell = initCell(headerCell, 0, y);
        y += 50;
        heatmapPanelLayout.add(cell);

    }
    x = 50;
    y = 50;
    for (String[] row : data) {
        for (String color : row) {
            JPanel cell = initCell(color, x, y);
            heatmapPanelLayout.add(cell);
            x += 50;
        }
        x = 50;
        y += 50;
    }

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(Color.WHITE);
    heatmapPanelLayout.paint(graphics);
    //        super.paint(graphics);
    byte[] imageData = null;

    try {

        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f));
        imageData = in.encode(image);
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
    }

    String base64 = Base64.encodeBytes(imageData);
    base64 = "data:image/png;base64," + base64;
    return base64;
    //
    //        JFrame frame = new JFrame();
    //        frame.setSize(1000, 1000);
    //        frame.add(heatmapPanelLayout);
    //        frame.setVisible(true);

    //        return "";
}

From source file:com.db2eshop.gui.dialog.ConfirmDialog.java

/**
 * <p>Constructor for ConfirmDialog.</p>
 *//* w ww  . java 2  s  . c om*/
public ConfirmDialog() {
    layout = new MigLayout("fill");

    this.setMinimumSize(new Dimension(600, 300));

    setLayout(layout);
    contentPane = new JPanel();
    contentPane.setLayout(new MigLayout("fill"));

    scrollPane = new JScrollPane(contentPane);
    add(scrollPane, "grow, push,wrap");

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new MigLayout("fill"));

    confirmButton = new JButton("Confirm");
    buttonPane.add(confirmButton, "span, split 2, growx");
    confirmButton.addActionListener(this);

    add(buttonPane, "growx, south");
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    addWindowListener(this);

    pack();

    ready = true;
}

From source file:edu.harvard.mcz.imagecapture.VerbatimListDialog.java

protected void init() {
    setTitle("Verbatim Transcriptions to parse into fields");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBounds(100, 100, 1000, 600);/*from w w  w. jav a 2  s.c o m*/
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    SpecimenLifeCycle sls = new SpecimenLifeCycle();
    table = new JTable(new VerbatimCountTableModel(sls.countDistinctVerbatimValues()));
    table.setDefaultRenderer(VerbatimCount.class, new ButtonRenderer("Edit"));
    table.setDefaultEditor(VerbatimCount.class, new ButtonEditor(ButtonEditor.OPEN_VERBATIM_CLASSIFY, this));
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(table);
    contentPanel.add(scrollPane, BorderLayout.CENTER);
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton cancelButton = new JButton("Close");
            cancelButton.setActionCommand("Close");
            cancelButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                }

            });
            buttonPane.add(cancelButton);
        }
    }
}

From source file:HtmlDemo.java

public HtmlDemo() {
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    String initialText = "<html>\n" + "Color and font test:\n" + "<ul>\n" + "<li><font color=red>red</font>\n"
            + "<li><font color=blue>blue</font>\n" + "<li><font color=green>green</font>\n"
            + "<li><font size=-2>small</font>\n" + "<li><font size=+2>large</font>\n" + "<li><i>italic</i>\n"
            + "<li><b>bold</b>\n" + "</ul>\n";

    htmlTextArea = new JTextArea(10, 20);
    htmlTextArea.setText(initialText);//from   w w w  . j  av a  2 s  .  c o  m
    JScrollPane scrollPane = new JScrollPane(htmlTextArea);

    JButton changeTheLabel = new JButton("Change the label");
    changeTheLabel.setMnemonic(KeyEvent.VK_C);
    changeTheLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
    changeTheLabel.addActionListener(this);

    theLabel = new JLabel(initialText) {
        public Dimension getPreferredSize() {
            return new Dimension(200, 200);
        }

        public Dimension getMinimumSize() {
            return new Dimension(200, 200);
        }

        public Dimension getMaximumSize() {
            return new Dimension(200, 200);
        }
    };
    theLabel.setVerticalAlignment(SwingConstants.CENTER);
    theLabel.setHorizontalAlignment(SwingConstants.CENTER);

    JPanel leftPanel = new JPanel();
    leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
    leftPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Edit the HTML, then click the button"),
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    leftPanel.add(scrollPane);
    leftPanel.add(Box.createRigidArea(new Dimension(0, 10)));
    leftPanel.add(changeTheLabel);

    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));
    rightPanel
            .setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A label with HTML"),
                    BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    rightPanel.add(theLabel);

    setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    add(leftPanel);
    add(Box.createRigidArea(new Dimension(10, 0)));
    add(rightPanel);
}

From source file:TRescaleOp.java

public TRescaleOp() {
    super();//  w w  w.  j  av  a2 s  .  c  o m
    Container container = getContentPane();

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

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

    brightenButton = new JButton("Brightness >>");
    brightenButton.addActionListener(new ButtonListener());
    darkenButton = new JButton("Brightness <<");
    darkenButton.addActionListener(new ButtonListener());

    contIncButton = new JButton("Contrast >>");
    contIncButton.addActionListener(new ButtonListener());
    contDecButton = new JButton("Contrast <<");
    contDecButton.addActionListener(new ButtonListener());

    panel.add(brightenButton);
    panel.add(darkenButton);
    panel.add(contIncButton);
    panel.add(contDecButton);

    container.add(BorderLayout.SOUTH, panel);

    addWindowListener(new WindowEventHandler());
    setSize(displayPanel.getWidth(), displayPanel.getHeight() + 10);
    show(); // Display the frame
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphGUI.java

/**
 * Load the GUI./*  w  w  w . ja  va2 s. c o m*/
 */
protected final void initGUI() {
    this.setLayout(new BorderLayout());
    this.add(createOptionPanel(), BorderLayout.NORTH);

    pnlGraph = new ChartPanel(null);
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.anchor = GridBagConstraints.NORTHWEST;
    panel.add(pnlGraph, constraints);
    panel.setBackground(Color.white);
    this.add(panel, BorderLayout.CENTER);
}

From source file:com.game.ui.views.UserDialog.java

public UserDialog(String message, JFrame frame) {
    setLayout(new BorderLayout(5, 5));
    setModalityType(ModalityType.APPLICATION_MODAL);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setResizable(false);/*from   w  w w.j  a v a2 s  . c  o m*/
    ImageIcon icon = null;
    try {
        icon = GameUtils.shrinkImage("warning.gif", 30, 30);
    } catch (IOException e) {
        System.out.println("Dialog : showDialogForMap(): Exception occured :" + e);
        e.printStackTrace();
    }
    JPanel panel = new JPanel();
    JLabel label = new JLabel(icon);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    label.setText(message);
    label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    label.setHorizontalAlignment(0);
    panel.add(label);
    add(panel, BorderLayout.NORTH);
    JPanel contentPanel = new JPanel();
    contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
    txt = new JTextField();
    txt.setPreferredSize(new Dimension(150, 30));
    txt.setAlignmentX(.5f);
    txt.setMaximumSize(new Dimension(150, 30));
    contentPanel.add(txt);
    contentPanel.add(Box.createVerticalStrut(10));
    JButton btn = new JButton("Submit.");
    btn.setAlignmentX(.5f);
    btn.setPreferredSize(new Dimension(50, 25));
    btn.addActionListener(this);
    validationMess = new JLabel("All fields are mandatory");
    validationMess.setVisible(false);
    validationMess.setForeground(Color.red);
    validationMess.setAlignmentX(.5f);
    contentPanel.add(btn);
    contentPanel.add(Box.createVerticalStrut(10));
    contentPanel.add(validationMess);
    contentPanel.add(Box.createVerticalGlue());
    add(contentPanel, BorderLayout.CENTER);
    pack();
    setSize(new Dimension(300, 200));
    setLocationRelativeTo(frame);
    setVisible(true);
}

From source file:medsavant.uhn.cancer.SetCommentStatusDialog.java

private JPanel getStatusEditorPanel() {
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(Box.createHorizontalGlue());
    statusIconPanel = new StatusIconPanel(ICON_WIDTH, ICON_HEIGHT, true, parentComment.isApproved(),
            parentComment.isIncluded(), parentComment.isDeleted());
    p.add(statusIconPanel);/*  ww  w .  j  ava 2s .  co m*/
    p.add(Box.createHorizontalGlue());
    return p;
}

From source file:CommonLayouts.java

public CommonLayouts() {
    super("Common Layout Managers");
    setSize(500, 380);/*www.  ja  va  2 s  .  c  o m*/

    JPanel desktop = new JPanel();
    getContentPane().add(desktop);

    JPanel fr1 = new JPanel();
    fr1.setBorder(new TitledBorder("FlowLayout"));
    fr1.setLayout(new FlowLayout());
    fr1.add(new JButton("1"));
    fr1.add(new JButton("2"));
    fr1.add(new JButton("3"));
    fr1.add(new JButton("4"));
    desktop.add(fr1, 0);

    JPanel fr2 = new JPanel();
    fr2.setBorder(new TitledBorder("GridLayout"));
    fr2.setLayout(new GridLayout(2, 2));
    fr2.add(new JButton("1"));
    fr2.add(new JButton("2"));
    fr2.add(new JButton("3"));
    fr2.add(new JButton("4"));
    desktop.add(fr2, 0);

    JPanel fr3 = new JPanel();
    fr3.setBorder(new TitledBorder("BorderLayout"));
    fr3.add(new JButton("1"), BorderLayout.NORTH);
    fr3.add(new JButton("2"), BorderLayout.EAST);
    fr3.add(new JButton("3"), BorderLayout.SOUTH);
    fr3.add(new JButton("4"), BorderLayout.WEST);
    desktop.add(fr3, 0);

    JPanel fr4 = new JPanel();
    fr4.setBorder(new TitledBorder("BoxLayout - X"));
    fr4.setLayout(new BoxLayout(fr4, BoxLayout.X_AXIS));
    fr4.add(new JButton("1"));
    fr4.add(Box.createHorizontalStrut(12));
    fr4.add(new JButton("2"));
    fr4.add(Box.createGlue());
    fr4.add(new JButton("3"));
    fr4.add(Box.createHorizontalGlue());
    fr4.add(new JButton("4"));
    desktop.add(fr4, 0);

    JPanel fr5 = new JPanel();
    fr5.setBorder(new TitledBorder("BoxLayout - Y"));
    fr5.setLayout(new BoxLayout(fr5, BoxLayout.Y_AXIS));
    fr5.add(new JButton("1"));
    fr5.add(Box.createVerticalStrut(10));
    fr5.add(new JButton("2"));
    fr5.add(Box.createGlue());
    fr5.add(new JButton("3"));
    fr5.add(Box.createVerticalGlue());
    fr5.add(new JButton("4"));
    desktop.add(fr5, 0);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}