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

public TColor() {
    sliderR = getSlider(0, 255, 0, 50, 5);
    sliderG = getSlider(0, 255, 0, 50, 5);
    sliderB = getSlider(0, 255, 0, 50, 5);
    sliderH = getSlider(0, 10, 0, 5, 1);
    sliderS = getSlider(0, 10, 0, 5, 1);
    sliderBr = getSlider(0, 10, 0, 5, 1);
    sliderAlpha = getSlider(0, 255, 255, 50, 5);

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(6, 2, 15, 0));

    panel.add(new JLabel("R-G-B Sliders (0 - 255)"));
    panel.add(new JLabel("H-S-B Sliders (ex-1)"));
    panel.add(sliderR);//from  w w  w.j  a v  a 2  s.  c  o m
    panel.add(sliderH);
    panel.add(sliderG);
    panel.add(sliderS);
    panel.add(sliderB);
    panel.add(sliderBr);

    panel.add(new JLabel("Alpha Adjustment (0 - 255): ", JLabel.RIGHT));
    panel.add(sliderAlpha);

    panel.add(new JLabel("RGB Value: ", JLabel.RIGHT));

    rgbValue.setBackground(Color.white);
    rgbValue.setForeground(Color.black);
    rgbValue.setOpaque(true);
    panel.add(rgbValue);

    add(panel, BorderLayout.SOUTH);
    add(canvas);
}

From source file:MainClass.java

public MainClass() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(350, 200);/*from w ww . j  a  v a 2  s  .  co m*/

    JTable table = new JTable(qtm);
    JScrollPane scrollpane = new JScrollPane(table);
    JPanel commandPanel = new JPanel();
    commandPanel.setLayout(new GridLayout(3, 2));
    commandPanel.add(new JLabel("Enter the Host URL: "));
    commandPanel.add(hostField = new JTextField());
    commandPanel.add(new JLabel("Enter your query: "));
    commandPanel.add(queryField = new JTextField());
    commandPanel.add(new JLabel("Click here to send: "));

    JButton jb = new JButton("Search");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            qtm.setHostURL(hostField.getText().trim());
            qtm.setQuery(queryField.getText().trim());
        }
    });
    commandPanel.add(jb);
    getContentPane().add(commandPanel, BorderLayout.NORTH);
    getContentPane().add(scrollpane, BorderLayout.CENTER);
}

From source file:MemComboBoxDemo.java

public MemComboBoxDemo() {
    super();//from   w  w  w.j a  v a 2  s .c o m
    setSize(300, 100);
    getContentPane().setLayout(new BorderLayout());

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(new JLabel("Address"));

    urlComboBox.load("addresses.dat");
    ComboBoxListener lst = new ComboBoxListener();
    urlComboBox.addActionListener(lst);

    MemComboAgent agent = new MemComboAgent(urlComboBox);

    p.add(urlComboBox);
    getContentPane().add(p, BorderLayout.NORTH);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            urlComboBox.save("addresses.dat");
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
    urlComboBox.grabFocus();
}

From source file:com.idealista.solrmeter.view.statistic.PieChartPanel.java

private Component createCustomizePanel() {
    JButton jButtonCustomize = new JButton(I18n.get("statistic.pieChartPanel.customize"));
    jButtonCustomize.addActionListener(new ActionListener() {

        @Override/*from ww  w  .  j  a  v a2s .c  om*/
        public void actionPerformed(ActionEvent e) {
            JDialogCustomizePieChart dialog = new JDialogCustomizePieChart(SolrMeterMain.mainFrame,
                    timeRangeStatistic);
            dialog.setVisible(true);
        }

    });

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 10));
    panel.add(Box.createHorizontalGlue());
    panel.add(jButtonCustomize);

    return panel;
}

From source file:TArea.java

public void init() {
    Container container = getContentPane();

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 2));

    resetButton = new JRadioButton("Reset", true);

    addButton = new JRadioButton("Add");
    subtractButton = new JRadioButton("Subtract");
    intersectButton = new JRadioButton("Intersect");
    exclusiveORButton = new JRadioButton("ExclusiveOR");

    ButtonGroup group = new ButtonGroup();
    group.add(resetButton);/*from ww w .  ja  va 2 s . c  o m*/
    group.add(addButton);
    group.add(subtractButton);
    group.add(intersectButton);
    group.add(exclusiveORButton);
    group.add(resetButton);

    resetButton.addActionListener(this);
    addButton.addActionListener(this);
    subtractButton.addActionListener(this);
    intersectButton.addActionListener(this);
    exclusiveORButton.addActionListener(this);

    panel.add(addButton);
    panel.add(subtractButton);
    panel.add(intersectButton);
    panel.add(exclusiveORButton);

    container.add(panel, BorderLayout.NORTH);
    container.add(resetButton, BorderLayout.SOUTH);

    canvas = new DrawingCanvas();
    container.add(canvas);
}

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

/**
 * Create the dialog./*from  www  . j  a va 2  s .c om*/
 */
public VerbatimToTranscribeDialog() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBounds(100, 100, 726, 557);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
        table = new JTable();
        SpecimenLifeCycle sls = new SpecimenLifeCycle();
        GenusSpeciesCountTableModel model = new GenusSpeciesCountTableModel(sls.countSpecimensForVerbatim());
        table.setModel(model);
        table.setDefaultRenderer(GenusSpeciesCount.class, new ButtonRenderer("Transcribe"));
        table.setDefaultEditor(GenusSpeciesCount.class,
                new ButtonEditor(ButtonEditor.OPEN_SPECIMEN_VERBATIM, this));
        contentPanel.add(table, 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:EditorPaneExample3.java

public EditorPaneExample3() {
    super("JEditorPane Example 3");

    pane = new JEditorPane();
    pane.setEditable(false); // Read-only
    getContentPane().add(new JScrollPane(pane), "Center");

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;//  w w w.j a v a 2  s .c  o m
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);

    c.gridx = 1;
    c.gridy = 0;
    c.gridwidth = 1;
    c.weightx = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;

    textField = new JTextField(32);
    panel.add(textField, c);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);

    getContentPane().add(panel, "South");

    // Change page based on text field
    textField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            String url = textField.getText();
            try {
                // Try to display the page
                loadingState.setText("Loading...");
                loadingState.paintImmediately(0, 0, loadingState.getSize().width,
                        loadingState.getSize().height);
                loadedType.setText("");
                loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height);
                pane.setPage(url);

                loadingState.setText("Loaded");
                loadedType.setText(pane.getContentType());
            } catch (IOException e) {
                JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url },
                        "File Open Error", JOptionPane.ERROR_MESSAGE);
                loadingState.setText("Failed");
            }
        }
    });
}

From source file:components.ComboBoxDemo2.java

public ComboBoxDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    String[] patternExamples = { "dd MMMMM yyyy", "dd.MM.yy", "MM/dd/yy", "yyyy.MM.dd G 'at' hh:mm:ss z",
            "EEE, MMM d, ''yy", "h:mm a", "H:mm:ss:SSS", "K:mm a,z", "yyyy.MMMMM.dd GGG hh:mm aaa" };

    currentPattern = patternExamples[0];

    //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:");

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setEditable(true);/*from  w ww. jav a2  s.  c  om*/
    patternList.addActionListener(this);

    //Create the UI for displaying result.
    JLabel resultLabel = new JLabel("Current Date/Time", JLabel.LEADING); //== LEFT
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Lay out everything.
    JPanel patternPanel = new JPanel();
    patternPanel.setLayout(new BoxLayout(patternPanel, BoxLayout.PAGE_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternPanel.add(patternList);

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

    patternPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    resultPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    add(patternPanel);
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(resultPanel);

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

    reformat();
}

From source file:menusearch.ui.MenuGraph.java

/**
 * Displays a LineChart based on the number of menus by years Data is
 * according to the menus currently being displayed on MenuResultsPage
 *
 * @param evt- When displayLineChart button is clicked
 *///from   ww w.ja v  a  2 s  .c om
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    try {
        MenuResultsPage mp = new MenuResultsPage();
        SearchMenusPanel x = new SearchMenusPanel();
        SearchParameters p = x.buildSearchParameters();
        ArrayList<Menu> search = mp.menuListResults(p);
        ArrayList<LocalDate> menu_date = null;
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (int i = 0; i < search.size(); i++) {
            menu_date.add(search.get(i).getMenu_date());
            int year = menu_date.get(i).getYear();
            dataset.addValue(year, "Years", "Number of Menus");
        }

        JFreeChart chart = ChartFactory.createLineChart("Number of Menus by Years", "Years", "Number of Menus",
                dataset, PlotOrientation.VERTICAL, false, true, true);
        BarRenderer renderer = null;
        CategoryPlot plot = null;
        renderer = new BarRenderer();
        ChartPanel chPanel = new ChartPanel(chart);
        chPanel.setVisible(true);
        chPanel.setPreferredSize(new Dimension(575, 300));
        chPanel.setMouseWheelEnabled(true);
        JPanel jPanel = new JPanel();
        jPanel.setLayout(new java.awt.BorderLayout());
        jPanel.add(chPanel, BorderLayout.CENTER);
        jPanel.validate();
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(MenuGraph.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(MenuGraph.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gui.SignUpGUI.java

private void addComponentToPanel(JPanel panel, JLabel label, JTextField textField) {
    panel.setLayout(new FlowLayout());
    panel.add(label);// ww  w.  j  av a 2 s. c  o  m
    panel.add(textField);
}