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:com.devoteam.srit.xmlloader.core.report.derived.StatCount.java

@Override
public JPanel generateLongRTStats() {
    // Panel we will return with all information of this counter
    JPanel panel = new JPanel();

    // Layout for this panel
    panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));

    // Color of background for this panel
    panel.setBackground(new java.awt.Color(248, 248, 248));

    // We add as a Tooltip the long description of this counter
    panel.setToolTipText(template.complete);

    // We add this html code as a JLabel in the panel
    panel.add(new JLabel(generateLongStringHTML()));

    // We return the panel
    return panel;
}

From source file:fungus.UtilizationChartFrame.java

public UtilizationChartFrame(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);/*  ww w .  j a v  a2 s.  c  o  m*/
    dataset.setIntervalWidth(simulationCycles);

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

    //XYSeriesCollection dataset;

    JFreeChart utilizationChart = ChartFactory.createXYLineChart("Utilization Metrics", "Cycle",
            "Average Utilization", dataset, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel utilizationChartPanel = new ChartPanel(utilizationChart);

    //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(utilizationChartPanel, 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:BorderDemo.java

public BorderDemo() {
    super("BorderDemo");
    Border blackline, etched, raisedbevel, loweredbevel, empty;

    //A border that puts 10 extra pixels at the sides and
    //bottom of each pane.
    Border paneEdge = BorderFactory.createEmptyBorder(0, 10, 10, 10);

    blackline = BorderFactory.createLineBorder(Color.black);
    etched = BorderFactory.createEtchedBorder();
    raisedbevel = BorderFactory.createRaisedBevelBorder();
    loweredbevel = BorderFactory.createLoweredBevelBorder();
    empty = BorderFactory.createEmptyBorder();

    //First pane: simple borders
    JPanel simpleBorders = new JPanel();
    simpleBorders.setBorder(paneEdge);/*  w  ww .  ja  va  2 s .  c  o  m*/
    simpleBorders.setLayout(new BoxLayout(simpleBorders, BoxLayout.Y_AXIS));

    addCompForBorder(blackline, "line border", simpleBorders);
    addCompForBorder(etched, "etched border", simpleBorders);
    addCompForBorder(raisedbevel, "raised bevel border", simpleBorders);
    addCompForBorder(loweredbevel, "lowered bevel border", simpleBorders);
    addCompForBorder(empty, "empty border", simpleBorders);

    //Second pane: matte borders
    JPanel matteBorders = new JPanel();
    matteBorders.setBorder(paneEdge);
    matteBorders.setLayout(new BoxLayout(matteBorders, BoxLayout.Y_AXIS));

    //XXX: We *should* size the component so that the
    //XXX: icons tile OK. Without that, the icons are
    //XXX: likely to be cut off and look bad.
    ImageIcon icon = new ImageIcon("images/left.gif"); //20x22
    Border border = BorderFactory.createMatteBorder(-1, -1, -1, -1, icon);
    addCompForBorder(border, "matte border (-1,-1,-1,-1,icon)", matteBorders);
    border = BorderFactory.createMatteBorder(1, 5, 1, 1, Color.red);
    addCompForBorder(border, "matte border (1,5,1,1,Color.red)", matteBorders);
    border = BorderFactory.createMatteBorder(0, 20, 0, 0, icon);
    addCompForBorder(border, "matte border (0,20,0,0,icon)", matteBorders);

    //Third pane: titled borders
    JPanel titledBorders = new JPanel();
    titledBorders.setBorder(paneEdge);
    titledBorders.setLayout(new BoxLayout(titledBorders, BoxLayout.Y_AXIS));
    TitledBorder titled;

    titled = BorderFactory.createTitledBorder("title");
    addCompForBorder(titled, "default titled border" + " (default just., default pos.)", titledBorders);

    titled = BorderFactory.createTitledBorder(blackline, "title");
    addCompForTitledBorder(titled, "titled line border" + " (centered, default pos.)", TitledBorder.CENTER,
            TitledBorder.DEFAULT_POSITION, titledBorders);

    titled = BorderFactory.createTitledBorder(etched, "title");
    addCompForTitledBorder(titled, "titled etched border" + " (right just., default pos.)", TitledBorder.RIGHT,
            TitledBorder.DEFAULT_POSITION, titledBorders);

    titled = BorderFactory.createTitledBorder(loweredbevel, "title");
    addCompForTitledBorder(titled, "titled lowered bevel border" + " (default just., above top)",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.ABOVE_TOP, titledBorders);

    titled = BorderFactory.createTitledBorder(empty, "title");
    addCompForTitledBorder(titled, "titled empty border" + " (default just., bottom)",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.BOTTOM, titledBorders);

    //Fourth pane: compound borders
    JPanel compoundBorders = new JPanel();
    compoundBorders.setBorder(paneEdge);
    compoundBorders.setLayout(new BoxLayout(compoundBorders, BoxLayout.Y_AXIS));
    Border redline = BorderFactory.createLineBorder(Color.red);

    Border compound;
    compound = BorderFactory.createCompoundBorder(raisedbevel, loweredbevel);
    addCompForBorder(compound, "compound border (two bevels)", compoundBorders);

    compound = BorderFactory.createCompoundBorder(redline, compound);
    addCompForBorder(compound, "compound border (add a red outline)", compoundBorders);

    titled = BorderFactory.createTitledBorder(compound, "title", TitledBorder.CENTER,
            TitledBorder.BELOW_BOTTOM);
    addCompForBorder(titled, "titled compound border" + " (centered, below bottom)", compoundBorders);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Simple", null, simpleBorders, null);
    tabbedPane.addTab("Matte", null, matteBorders, null);
    tabbedPane.addTab("Titled", null, titledBorders, null);
    tabbedPane.addTab("Compound", null, compoundBorders, null);
    tabbedPane.setSelectedIndex(0);

    getContentPane().add(tabbedPane, BorderLayout.CENTER);
}

From source file:com.emental.mindraider.ui.dialogs.SearchConceptAnnotation.java

/**
 * Constructor.//  w w  w  . j  ava 2s  . c  o  m
 */
public SearchConceptAnnotation(AbstractTextAnnotationRenderer renderer) {
    super("Search Annotation");

    this.renderer = renderer;

    JPanel dialogPanel = new JPanel();
    dialogPanel.setBorder(new EmptyBorder(5, 10, 0, 10));
    dialogPanel.setLayout(new BorderLayout());

    JPanel contentAndButtons = new JPanel(new GridLayout(2, 1));
    JPanel contentPanel = new JPanel(new BorderLayout());

    // 1a.
    // TODO add help like in eclipse
    contentPanel.add(new JLabel(Messages.getString("FtsJDialog.searchString")), BorderLayout.NORTH);
    // 1b.
    searchCombo = new JComboBox(history.toArray());
    searchCombo.setSelectedItem("");
    searchCombo.setPreferredSize(new Dimension(200, 18));
    searchCombo.setEditable(true);
    searchCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if ("comboBoxEdited".equals(e.getActionCommand())) {
                search();
            }
        }
    });
    contentPanel.add(searchCombo, BorderLayout.SOUTH);
    contentAndButtons.add(contentPanel);

    // 2.
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5));
    JButton searchButton = new JButton(Messages.getString("FtsJDialog.searchButton"));
    searchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            search();
        }
    });
    p.add(searchButton);

    JButton cancelButton = new JButton(Messages.getString("FtsJDialog.cancel"));
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    p.add(cancelButton);

    contentAndButtons.add(p);

    dialogPanel.add(contentAndButtons, BorderLayout.CENTER);

    getContentPane().add(dialogPanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:BasicDnD.java

protected JPanel createVerticalBoxPanel() {
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    return p;//w  w w .j  a  v  a  2s.  co  m
}

From source file:postenergy.PostEnergy.java

private void initUI() {

    /* Definitions */
    JPanel panel = new JPanel();
    getContentPane().add(panel);//from   w  w w  . j  a va 2s  .c  om

    panel.setLayout(null);

    /* Basic elements */

    JButton getBatteryInfo = new JButton("Get Battery Info");
    getBatteryInfo.setBounds(0, 60, 180, 30);
    getBatteryInfo.setToolTipText("Get Battery Info");
    getBatteryInfo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            System.out.println("getBatteryInfo button pressed!");

            ProcessBuilder pbs = new ProcessBuilder("/Users/thomas/Development/script.sh");

            try {
                Process p = pbs.start();
                BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
                StringBuilder builder = new StringBuilder();
                String line = null;
                try {
                    while ((line = br.readLine()) != null) {
                        builder.append(line);
                        builder.append(System.getProperty("line.separator"));
                    }
                } catch (IOException ex) {
                    Logger.getLogger(PostEnergy.class.getName()).log(Level.SEVERE, null, ex);
                }
                String result = builder.toString();
                System.out.println("Result: " + result);

                // Send as POST request
                String[] paramNames = new String[] { "t", "h" };
                String[] paramVals = new String[] { result, result + 100 };

                PostHttpClient("mindass", paramNames, paramVals);
            } catch (IOException ex) {
                System.out.println("Error with the processbuilder!");
                Logger.getLogger(PostEnergy.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    });

    panel.add(getBatteryInfo);

    JButton sendPost = new JButton("Send Post");
    sendPost.setBounds(0, 30, 180, 30);
    sendPost.setToolTipText("Send Post");

    sendPost.addActionListener(new ActionListener() {
        @Override

        public void actionPerformed(ActionEvent event) {
            System.out.println("sendPost button pressed!");

            PostHttpClient("mindass", new String[] { "t", "h" }, new String[] { "23", "44" });

        }

    });

    panel.add(sendPost);

    JButton quitButton = new JButton("Quit");
    quitButton.setBounds(0, 0, 80, 30);
    quitButton.setToolTipText("Quit iPower");

    quitButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            System.out.println("Quit button pressed!");
            System.exit(0);
        }
    });

    panel.add(quitButton);

    /* Set init */
    setTitle("iPower");
    setSize(300, 200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel.java

/**
 *  ------------------------------//w ww.  j a  va2 s .c om
 *  |  [      controller      ]  |
 *  | [ ] front processor 1      |
 *  | [ ] front processor 2      |
 *  | [ ] end processor 1        |
 *  | [ ] end processor 2        |
 * 
 *  | [+]                   [-]  |
 *  |  ________________________  |
 *  | | Enabled | Pattern      | |
 *  | |  [y]    | T\d+         | |
 *  | |  [n]    | M30          | |
 *  |  ------------------------  |
 *  |____________________________|
 */
@Override
protected void updateComponentsInternal(Settings s) {
    this.removeAll();
    initCustomRemoverTable(customRemoverTable);
    setLayout(new MigLayout("wrap 1, inset 5, fillx", "fill"));

    super.addIgnoreChanges(controllerConfigs);

    ConfigTuple ct = configFiles.get(controllerConfigs.getSelectedItem());
    ProcessorConfigGroups pcg = ct.loader.getProcessorConfigs();
    System.out.println(ct.file);

    for (ProcessorConfig pc : pcg.Front) {
        add(new ProcessorConfigCheckbox(pc, CommandProcessorLoader.getHelpForConfig(pc)));
    }

    for (ProcessorConfig pc : pcg.End) {
        add(new ProcessorConfigCheckbox(pc, CommandProcessorLoader.getHelpForConfig(pc)));
    }

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new MigLayout("wrap 3", "grow, fill", ""));
    add(buttonPanel, add);
    add(buttonPanel, new JLabel());
    add(buttonPanel, remove);
    addIgnoreChanges(buttonPanel);

    DefaultTableModel model = (DefaultTableModel) this.customRemoverTable.getModel();
    for (ProcessorConfig pc : pcg.Custom) {
        Boolean enabled = pc.enabled;
        String pattern = "";
        if (pc.args != null && !pc.args.get("pattern").isJsonNull()) {
            pattern = pc.args.get("pattern").getAsString();
        }
        model.addRow(new Object[] { enabled, pattern });
    }
    addIgnoreChanges(new JScrollPane(customRemoverTable), "height 100");

    SwingUtilities.updateComponentTreeUI(this);
}

From source file:components.ListDialog.java

private ListDialog(Frame frame, Component locationComp, String labelText, String title, Object[] data,
        String initialValue, String longValue) {
    super(frame, title, true);

    //Create and initialize the buttons.
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);
    ///*  w w  w.ja  v a 2 s .c  om*/
    final JButton setButton = new JButton("Set");
    setButton.setActionCommand("Set");
    setButton.addActionListener(this);
    getRootPane().setDefaultButton(setButton);

    //main part of the dialog
    list = new JList(data) {
        //Subclass JList to workaround bug 4832765, which can cause the
        //scroll pane to not let the user easily scroll up to the beginning
        //of the list.  An alternative would be to set the unitIncrement
        //of the JScrollBar to a fixed value. You wouldn't get the nice
        //aligned scrolling, but it should work.
        public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
            int row;
            if (orientation == SwingConstants.VERTICAL && direction < 0
                    && (row = getFirstVisibleIndex()) != -1) {
                Rectangle r = getCellBounds(row, row);
                if ((r.y == visibleRect.y) && (row != 0)) {
                    Point loc = r.getLocation();
                    loc.y--;
                    int prevIndex = locationToIndex(loc);
                    Rectangle prevR = getCellBounds(prevIndex, prevIndex);

                    if (prevR == null || prevR.y >= r.y) {
                        return 0;
                    }
                    return prevR.height;
                }
            }
            return super.getScrollableUnitIncrement(visibleRect, orientation, direction);
        }
    };

    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    if (longValue != null) {
        list.setPrototypeCellValue(longValue); //get extra space
    }
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(-1);
    list.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                setButton.doClick(); //emulate button click
            }
        }
    });
    JScrollPane listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(250, 80));
    listScroller.setAlignmentX(LEFT_ALIGNMENT);

    //Create a container so that we can add a title around
    //the scroll pane.  Can't add a title directly to the
    //scroll pane because its background would be white.
    //Lay out the label and scroll pane from top to bottom.
    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    JLabel label = new JLabel(labelText);
    label.setLabelFor(list);
    listPane.add(label);
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(listScroller);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    //Lay out the buttons from left to right.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(cancelButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(setButton);

    //Put everything together, using the content pane's BorderLayout.
    Container contentPane = getContentPane();
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //Initialize values.
    setValue(initialValue);
    pack();
    setLocationRelativeTo(locationComp);
}

From source file:com.l2jfree.config.gui.Configurator.java

public Configurator(ConfigClassInfo configClassInfo) {
    _configClassInfo = configClassInfo;//from  ww  w  .jav a 2  s. co m

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    {
        final JMenuBar jMenuBar = new JMenuBar();

        {
            jMenuBar.add(getLoadJButton());
        }
        {
            jMenuBar.add(getRefreshJButton());
        }
        {
            jMenuBar.add(Box.createHorizontalGlue());
        }
        {
            jMenuBar.add(getSaveJButton());
        }
        {
            jMenuBar.add(getStoreJButton());
        }

        setJMenuBar(jMenuBar);
    }

    {
        final JPanel jPanel = new JPanel();

        jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));

        {
            for (ConfigFieldInfo info : _configClassInfo.getConfigFieldInfos()) {
                final ConfigFieldInfoView view = new ConfigFieldInfoView(info);

                // LOW implement

                jPanel.add(view);
            }
        }

        add(new JScrollPane(jPanel));
    }

    pack();
    setSize(600, 400);
    setLocationByPlatform(true);
    setVisible(true);
}

From source file:com.devoteam.srit.xmlloader.core.report.derived.StatPercent.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.cumulated)));
    panel.add(new JLabel(Utils.formatdouble(this.counter.globalDataset.getValue()) + "%"));
    panel.setToolTipText(generateRTStatsToolTip());

    addMouseListenerForGraph(panel);/*  ww  w.j a  va 2 s. c  om*/

    return panel;
}