Example usage for java.awt Container setLayout

List of usage examples for java.awt Container setLayout

Introduction

In this page you can find the example usage for java.awt Container setLayout.

Prototype

public void setLayout(LayoutManager mgr) 

Source Link

Document

Sets the layout manager for this container.

Usage

From source file:com.zigabyte.stock.stratplot.StockMarketHistoryViewer.java

private void initLayout() {
    Container content = this.getContentPane();
    content.setLayout(new BorderLayout());
    content.add(new JLabel("Select stock to view chart"), BorderLayout.NORTH);
    content.add(new JScrollPane(stockList), BorderLayout.LINE_START);
    content.add(chartPanel, BorderLayout.CENTER);
    this.setSize(1024, 768);
}

From source file:UndoableToggleApp2.java

public UndoableToggleApp2() {

    // Create some toggle buttons (and subclasses)
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    // Add our listener to each toggle button
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//from   w  ww .  j  ava 2s . c  om
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    // Lay out the buttons
    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    // Create undo and redo buttons (initially disabled)
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    endButton = new JButton("End");
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);
    endButton.setEnabled(false);

    // Add a listener to the undo button. It attempts to call undo() on the
    // current edit, then enables/disables the undo/redo buttons as
    // appropriate.
    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Add a redo listener: just like the undo listener, but for redo this
    // time.
    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    // Add an end listener. This listener will call end() on the
    // CompoundEdit
    // and update the undo/redo buttons.
    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Layout the undo/redo/end buttons
    Box undoRedoEndBox = new Box(BoxLayout.X_AXIS);
    undoRedoEndBox.add(Box.createGlue());
    undoRedoEndBox.add(undoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(redoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(endButton);
    undoRedoEndBox.add(Box.createGlue());

    // Layout the main frame
    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoEndBox, BorderLayout.SOUTH);
    setSize(400, 150);
}

From source file:org.sikuli.ide.extmanager.ExtensionManagerFrame.java

void createComponents() {
    Container pane;

    pane = getContentPane();/*from   ww w .j  av a 2s  .  c  o m*/
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

    try {

        // Populate the list of extensions
        _extensions = retrieveExtensions();

        for (ExtensionItem ext : _extensions) {
            pane.add(ext);
            ;
        }

        // Select the first one
        select(0);

    } catch (IOException io) {

        String msg = "Unable to load extensions from the server: " + io.getMessage();
        JTextField txt = new JTextField(msg);
        txt.setBackground(null);
        txt.setBorder(null);
        txt.setEditable(false);
        pane.add(txt);
    }

    JPanel bottomBar = new JPanel();
    bottomBar.setLayout(new BorderLayout());
    bottomBar.setMinimumSize(new Dimension(400, 20));
    JButton closeBtn = new JButton("Close");

    closeBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            dispose();
        }

    });

    closeBtn.setFocusable(false);
    bottomBar.add(closeBtn, BorderLayout.LINE_END);
    pane.add(bottomBar);

}

From source file:org.apache.commons.httpclient.contrib.proxy.PluginProxyTestApplet.java

@Override
public void init() {
    Container content = getContentPane();
    content.setLayout(new BorderLayout());

    // Proxy info table
    grid = getPanel(new GridLayout(2, 3, 2, 2));
    grid.add(getHeaderLabel("URL"));
    grid.add(getHeaderLabel("Proxy Host"));
    grid.add(getHeaderLabel("Proxy Port"));
    grid.add(urlTextField);//from   ww  w .j  a va 2s .  c  om
    hostLabel = getLabel("");
    portLabel = getLabel("");
    grid.add(hostLabel);
    grid.add(portLabel);
    grid.validate();
    content.add(grid, BorderLayout.CENTER);

    // Button panel - SOUTH
    JPanel buttonPanel = getPanel(new FlowLayout());
    JButton button = new JButton("Detect Proxy");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    detectProxy();
                }
            });
        }
    });
    buttonPanel.add(button);
    content.add(buttonPanel, BorderLayout.SOUTH);

    // version panel - NORTH
    JPanel versionPanel = getPanel(new FlowLayout());
    String javaVersion = System.getProperty("java.runtime.version");
    JLabel versionLabel = getLabel("Java Version: " + javaVersion);
    versionPanel.add(versionLabel);
    content.add(versionPanel, BorderLayout.NORTH);
    validate();

    super.setSize(400, 100);
}

From source file:CompassButtons.java

public CompassButtons(String terrain) {
    super("SpringLayout Compass Demo");
    setSize(500, 300);/*from www  .j  av  a2s .c o m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    SpringLayout sl = new SpringLayout();
    Container c = getContentPane();
    c.setLayout(sl);

    int offset = 50; // gap between buttons and outside edge
    int w = 80; // width of buttons
    int h = 26; // height of buttons
    int border = 3; // border around viewport

    Spring offsetS = Spring.constant(offset);
    Spring borderS = Spring.constant(border);
    Spring widthS = Spring.constant(w);
    Spring halfWidthS = FractionSpring.half(widthS);
    Spring heightS = Spring.constant(h);
    Spring halfHeightS = FractionSpring.half(heightS);
    Spring leftEdgeS = sl.getConstraint(SpringLayout.WEST, c);
    Spring topEdgeS = sl.getConstraint(SpringLayout.NORTH, c);
    Spring rightEdgeS = sl.getConstraint(SpringLayout.EAST, c);
    Spring bottomEdgeS = sl.getConstraint(SpringLayout.SOUTH, c);
    Spring xCenterS = FractionSpring.half(rightEdgeS);
    Spring yCenterS = FractionSpring.half(bottomEdgeS);
    Spring leftBorder = Spring.sum(leftEdgeS, borderS);
    Spring topBorder = Spring.sum(topEdgeS, borderS);

    Spring northX = Spring.sum(xCenterS, Spring.minus(halfWidthS));
    Spring southY = Spring.sum(bottomEdgeS, Spring.minus(Spring.sum(heightS, offsetS)));
    Spring eastX = Spring.sum(rightEdgeS, Spring.minus(Spring.sum(widthS, offsetS)));
    Spring eastY = Spring.sum(yCenterS, Spring.minus(halfHeightS));

    c.add(nb, new SpringLayout.Constraints(northX, offsetS, widthS, heightS));
    c.add(sb, new SpringLayout.Constraints(northX, southY, widthS, heightS));

    c.add(wb);
    sl.getConstraints(wb).setX(offsetS);
    sl.getConstraints(wb).setY(eastY);
    sl.getConstraints(wb).setWidth(widthS);
    sl.getConstraints(wb).setHeight(heightS);

    c.add(eb);
    sl.getConstraints(eb).setX(eastX);
    sl.getConstraints(eb).setY(eastY);
    sl.getConstraints(eb).setWidth(widthS);
    sl.getConstraints(eb).setHeight(heightS);

    c.add(viewport); // this sets a bounds of (0,0,pref_width,pref_height)
    // The order here is important...need to have a valid width and height
    // in place before binding the (x,y) location
    sl.putConstraint(SpringLayout.SOUTH, viewport, Spring.minus(borderS), SpringLayout.SOUTH, c);
    sl.putConstraint(SpringLayout.EAST, viewport, Spring.minus(borderS), SpringLayout.EAST, c);
    sl.putConstraint(SpringLayout.NORTH, viewport, topBorder, SpringLayout.NORTH, c);
    sl.putConstraint(SpringLayout.WEST, viewport, leftBorder, SpringLayout.WEST, c);

    ImageIcon icon = new ImageIcon(getClass().getResource(terrain));
    viewport.setView(new JLabel(icon));

    // Hook up the buttons. See the CompassScroller class (on-line) for
    // details
    // on controlling the viewport.
    nb.setActionCommand(CompassScroller.NORTH);
    sb.setActionCommand(CompassScroller.SOUTH);
    wb.setActionCommand(CompassScroller.WEST);
    eb.setActionCommand(CompassScroller.EAST);
    CompassScroller scroller = new CompassScroller(viewport);
    nb.addActionListener(scroller);
    sb.addActionListener(scroller);
    eb.addActionListener(scroller);
    wb.addActionListener(scroller);

    setVisible(true);
}

From source file:GCWrapper.java

/**
 * Creates and lays out components in the container. See the comments below
 * for an organizational overview by panel.
 *//*from w w  w .  jav a2s .co  m*/
private void initComponents(Container c) {
    c.setLayout(new BorderLayout());
    // Graphics Config
    JPanel gcPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    c.add(gcPanel, BorderLayout.NORTH);
    gcSelection.setPreferredSize(new Dimension(400, 30));
    gcPanel.add(gcSelection);
    // Capabilities
    JPanel capsPanel = new JPanel(new BorderLayout());
    c.add(capsPanel, BorderLayout.CENTER);
    // Image Capabilities
    JPanel imageCapsPanel = new JPanel(new GridLayout(2, 1));
    capsPanel.add(imageCapsPanel, BorderLayout.NORTH);
    imageCapsPanel.setBorder(BorderFactory.createTitledBorder("Image Capabilities"));
    imageAccelerated.setEnabled(false);
    imageCapsPanel.add(imageAccelerated);
    imageTrueVolatile.setEnabled(false);
    imageCapsPanel.add(imageTrueVolatile);
    // Buffer Capabilities
    JPanel bufferCapsPanel = new JPanel(new BorderLayout());
    capsPanel.add(bufferCapsPanel, BorderLayout.CENTER);
    bufferCapsPanel.setBorder(BorderFactory.createTitledBorder("Buffer Capabilities"));
    // Buffer Access
    JPanel bufferAccessCapsPanel = new JPanel(new GridLayout(3, 1));
    bufferAccessCapsPanel.setPreferredSize(new Dimension(300, 88));
    bufferCapsPanel.add(bufferAccessCapsPanel, BorderLayout.NORTH);
    // Flipping
    JPanel flippingPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    bufferAccessCapsPanel.add(flippingPanel);
    flippingPanel.add(flipping);
    flipping.setEnabled(false);
    flippingPanel.add(flippingMethod);
    // Full-screen
    JPanel fsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    bufferAccessCapsPanel.add(fsPanel);
    JPanel indentPanel = new JPanel();
    indentPanel.setPreferredSize(new Dimension(30, 30));
    fsPanel.add(indentPanel);
    fsPanel.add(fullScreen);
    fullScreen.setEnabled(false);
    // Multi-buffering
    JPanel mbPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    bufferAccessCapsPanel.add(mbPanel);
    indentPanel = new JPanel();
    indentPanel.setPreferredSize(new Dimension(30, 30));
    mbPanel.add(indentPanel);
    mbPanel.add(multiBuffer);
    multiBuffer.setEnabled(false);
    // Front and Back Buffer Capabilities
    JPanel buffersPanel = new JPanel(new GridLayout(1, 2));
    bufferCapsPanel.add(buffersPanel, BorderLayout.CENTER);
    // Front Buffer
    JPanel fbPanel = new JPanel(new GridLayout(2, 1));
    fbPanel.setBorder(BorderFactory.createTitledBorder("Front Buffer"));
    buffersPanel.add(fbPanel);
    fbPanel.add(fbAccelerated);
    fbAccelerated.setEnabled(false);
    fbPanel.add(fbTrueVolatile);
    fbTrueVolatile.setEnabled(false);
    // Back Buffer
    JPanel bbPanel = new JPanel(new GridLayout(2, 1));
    bbPanel.setPreferredSize(new Dimension(250, 80));
    bbPanel.setBorder(BorderFactory.createTitledBorder("Back and Intermediate Buffers"));
    buffersPanel.add(bbPanel);
    bbPanel.add(bbAccelerated);
    bbAccelerated.setEnabled(false);
    bbPanel.add(bbTrueVolatile);
    bbTrueVolatile.setEnabled(false);
}

From source file:phex.gui.dialogs.AboutDialog.java

/**
 * //  w  ww  . ja v a  2s. c  om
 */
private void prepareComponent() {
    CloseEventHandler closeEventHandler = new CloseEventHandler();
    addWindowListener(closeEventHandler);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());
    JPanel contentPanel = new JPanel();
    //JPanel contentPanel = new FormDebugPanel();
    contentPane.add(contentPanel, BorderLayout.CENTER);

    CellConstraints cc = new CellConstraints();
    FormLayout layout = new FormLayout("4dlu, fill:d:grow, 4dlu", // columns
            "p, p, 2dlu, p, 4dlu, p, 4dlu"); //row
    PanelBuilder contentPB = new PanelBuilder(layout, contentPanel);

    Object[] objArr = { PrivateNetworkConstants.PRIVATE_BUILD_ID + VersionUtils.getProgramVersion(),
            VersionUtils.getBuild() };
    DialogBanner banner = new DialogBanner("Phex",
            Localizer.getFormatedString("AboutPhex_VersionInfo", objArr));
    contentPB.add(banner, cc.xywh(1, 1, 3, 1));

    contentPB.add(new JSeparator(), cc.xywh(1, 2, 3, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    contentPB.add(tabbedPane, cc.xy(2, 4));

    JButton closeBtn = new JButton(Localizer.getString("Close"));
    closeBtn.addActionListener(closeEventHandler);
    contentPB.add(ButtonBarFactory.buildCloseBar(closeBtn), cc.xy(2, 6));

    JPanel aboutPanel = new JPanel();
    layout = new FormLayout("4dlu, fill:d:grow, 4dlu", // columns
            "4dlu, p, 4dlu"); //row
    PanelBuilder aboutPB = new PanelBuilder(layout, aboutPanel);
    tabbedPane.addTab(Localizer.getString("AboutPhex_About"), aboutPanel);

    Object[] objArr2 = { Res.getStr("Program.Url") };
    HTMLMultiLinePanel aboutHtml = new HTMLMultiLinePanel(
            Localizer.getFormatedString("AboutPhex_AboutText", objArr2));
    aboutPB.add(aboutHtml, cc.xy(2, 2));

    JPanel envPanel = new JPanel();
    layout = new FormLayout("2dlu, fill:d:grow, 2dlu", // columns
            "2dlu, p, 2dlu, p, 2dlu"); //row
    PanelBuilder envPB = new PanelBuilder(layout, envPanel);
    tabbedPane.addTab(Localizer.getString("AboutPhex_Environment"), envPanel);

    environmentInfo = new JTextArea(12, 55);
    environmentInfo.setEditable(false);
    envPB.add(new JScrollPane(environmentInfo), cc.xy(2, 2));

    StringBuffer envTextBuffer = new StringBuffer();
    Properties pros = System.getProperties();
    ArrayList<String> list = new ArrayList(pros.keySet());
    Collections.sort(list);
    Iterator<String> iterator = list.iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        String value = (String) pros.get(key);
        envTextBuffer.append(key).append(" = ").append(value).append(SystemUtils.LINE_SEPARATOR);
    }
    environmentInfo.setText(envTextBuffer.toString());
    environmentInfo.setCaretPosition(0);

    JButton copyBtn = new JButton(Localizer.getString("Copy"));
    copyBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Toolkit.getDefaultToolkit().getSystemClipboard()
                    .setContents(new StringSelection(environmentInfo.getText()), null);
        }
    });
    envPB.add(ButtonBarFactory.buildLeftAlignedBar(copyBtn), cc.xy(2, 4));

    pack();
    setLocationRelativeTo(getParent());
}

From source file:pl.otros.logview.gui.markers.editor.NewMarkerAction.java

@Override
public void actionPerformed(ActionEvent e) {
    final JFrame f = new JFrame("Create new marker");
    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    Container contentPane = f.getContentPane();
    final MarkerEditor editor = new MarkerEditor();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(editor);// w  w  w .  j av  a  2 s  .  c o m

    JButton save = new JButton("Save");
    save.addActionListener(new ActionListener() {

        private final PluginableElementsContainer<AutomaticMarker> markersContainser = AllPluginables
                .getInstance().getMarkersContainser();

        @Override
        public void actionPerformed(ActionEvent arg0) {

            int showSaveDialog = chooser.showSaveDialog((Component) arg0.getSource());
            if (showSaveDialog != JFileChooser.APPROVE_OPTION) {
                return;
            }
            File saveFile = chooser.getSelectedFile();
            Properties markerPropertiesFromView = editor.getMarkerPropertiesFromView();

            try {
                saveMarker(saveFile, markerPropertiesFromView);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(f, "Error saving marker: " + e.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            try {
                AutomaticMarker marker = AutomaticMarkerLoader
                        .loadPropertyBasedMarker(markerPropertiesFromView);
                markersContainser.addElement(marker);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(f, "Error creating marker: " + e.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            f.dispose();
        }
    });
    contentPane.add(save, BorderLayout.SOUTH);

    f.pack();

    f.setVisible(true);
}

From source file:com.heatonresearch.aifh.examples.rbf.LearnIrisAnnealROC.java

public LearnIrisAnnealROC() {
    this.setSize(640, 480);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setTitle("Iris Classify ROC");
    Container content = this.getContentPane();
    content.setLayout(new BorderLayout());

    this.dataset = new XYSeriesCollection();
    this.dataSeries1 = new XYSeries("Threshold");
    this.dataset.addSeries(this.dataSeries1);

    final JFreeChart lineChart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title
            FPR, // x axis label
            TPR, // y axis label
            this.dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );// ww  w .j  ava 2  s.c  o m

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    content.add(chartPanel, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(this.buttonAnneal = new JButton("Anneal"));
    buttonPanel.add(this.buttonReset = new JButton("Reset"));
    this.buttonAnneal.addActionListener(this);
    this.buttonReset.addActionListener(this);
    content.add(buttonPanel, BorderLayout.SOUTH);

    this.training = loadIrisData();

    this.network = new RBFNetwork(4, 4, 1);
    this.network.reset(new MersenneTwisterGenerateRandom());

    final ScoreFunction score = new ScoreRegressionData(this.training);
    this.trainer = new TrainAnneal(this.network, score);
}

From source file:op.care.supervisor.DlgHOReport.java

/**
 * This method is called from within the constructor to
 * initialize the form./*from   www  . j a  v a  2 s  .  co m*/
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the PrinterForm Editor.
 */
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
    jScrollPane1 = new JScrollPane();
    txtReport = new JTextPane();
    panel1 = new JPanel();
    btnCancel = new JButton();
    btnSave = new JButton();

    //======== this ========
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            thisWindowClosing(e);
        }
    });
    Container contentPane = getContentPane();
    contentPane.setLayout(new FormLayout("default, $lcgap, default:grow, $lcgap, default",
            "2*(default, $lgap), fill:default:grow, $lgap, fill:default, $lgap, default"));

    //======== jScrollPane1 ========
    {
        jScrollPane1.setViewportView(txtReport);
    }
    contentPane.add(jScrollPane1, CC.xy(3, 5));

    //======== panel1 ========
    {
        panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));

        //---- btnCancel ----
        btnCancel.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/cancel.png")));
        btnCancel.setText(null);
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                btnCancelActionPerformed(e);
            }
        });
        panel1.add(btnCancel);

        //---- btnSave ----
        btnSave.setIcon(new ImageIcon(getClass().getResource("/artwork/22x22/apply.png")));
        btnSave.setText(null);
        btnSave.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                btnSaveActionPerformed(e);
            }
        });
        panel1.add(btnSave);
    }
    contentPane.add(panel1, CC.xy(3, 7, CC.RIGHT, CC.DEFAULT));
    setSize(462, 379);
    setLocationRelativeTo(null);
}