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

@Override
public void init() {
    tableModel = new SampleTableModel();
    // create javafx panel for charts
    chartFxPanel = new JFXPanel();
    chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT));

    //JTable/*from  w ww . j a v  a  2  s  .c  o m*/
    JTable table = new JTable(tableModel);
    table.setAutoCreateRowSorter(true);
    table.setGridColor(Color.DARK_GRAY);
    SwingInterop.DecimalFormatRenderer renderer = new SwingInterop.DecimalFormatRenderer();
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.getColumnModel().getColumn(i).setCellRenderer(renderer);
    }
    JScrollPane tablePanel = new JScrollPane(table);
    tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT));

    JPanel chartTablePanel = new JPanel();
    chartTablePanel.setLayout(new BorderLayout());

    //Split pane that holds both chart and table
    JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    jsplitPane.setTopComponent(chartTablePanel);
    jsplitPane.setBottomComponent(tablePanel);
    jsplitPane.setDividerLocation(410);
    chartTablePanel.add(chartFxPanel, BorderLayout.CENTER);

    //          add(tablePanel, BorderLayout.CENTER);
    add(jsplitPane, BorderLayout.CENTER);

    // create JavaFX scene
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            createScene();
        }
    });
}

From source file:com.aw.swing.mvp.grid.GridManager.java

private void configureGridTitleColor() {
    JPanel pnlGrid = ipView.getPnlGrid(gridIndex);
    pnlGrid.setBorder(BorderFactory.createLineBorder(new Color(131, 172, 219)));

    JPanel pnlTitGrid = ipView.getPnlTitGrid(gridIndex);
    pnlTitGrid.setBackground(new Color(131, 172, 219));
    pnlTitGrid.setLayout(
            new FormLayout("fill:16dlu:noGrow,left:4dlu:noGrow,fill:d:grow,left:4dlu:noGrow,right:pref:grow",
                    "center:16dlu:noGrow"));
    JLabel lblTitGrid = ipView.getLblTitGrid(gridIndex);
    lblTitGrid.setFont(new Font(lblTitGrid.getFont().getName(), Font.BOLD, 14));
    lblTitGrid.setForeground(Color.black);

    numRecords = new JLabel("");
    numRecords.setFont(new Font(lblTitGrid.getFont().getName(), Font.BOLD, 14));
    numRecords.setForeground(Color.black);
    numRecords.setVisible(showTotalRegistros);

    pnlTitGrid.remove(lblTitGrid);//from  ww  w .  ja v  a 2 s  . co  m
    CellConstraints cc = new CellConstraints();
    pnlTitGrid.add(lblTitGrid, cc.xy(3, 1));
    pnlTitGrid.add(numRecords, cc.xy(5, 1));

}

From source file:de.codesourcery.jasm16.ide.ui.views.CPUView.java

protected JPanel createPanel() {
    textArea.setFont(getMonospacedFont());
    textArea.setEditable(false);//ww  w  . j  a v  a2s.c  o m
    setColors(textArea);

    final JPanel panel = new JPanel();
    setColors(panel);
    panel.setLayout(new GridBagLayout());
    final GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    panel.add(textArea, cnstrs);
    return panel;
}

From source file:bazaar4idea.ui.BzrPushDialog.java

/** Method generated by IntelliJ IDEA GUI Designer
 * >>> IMPORTANT!! <<<
 * DO NOT edit this method OR call it in your code!
 * @noinspection ALL/*  ww w  .j  a  va  2s  .  co  m*/
 */
private void $$$setupUI$$$() {
    contentPanel = new JPanel();
    contentPanel.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
    final JPanel panel1 = new JPanel();
    panel1.setLayout(new GridLayoutManager(5, 1, new Insets(0, 0, 0, 0), -1, -1));
    contentPanel.add(panel1,
            new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
                    null, 0, false));
    final Spacer spacer1 = new Spacer();
    panel1.add(spacer1,
            new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
                    GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
    final JLabel label1 = new JLabel();
    label1.setText("Destination Repository URL:");
    label1.setDisplayedMnemonic('D');
    label1.setDisplayedMnemonicIndex(0);
    panel1.add(label1, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
            GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    repositoryTxt = new JTextField();
    panel1.add(repositoryTxt,
            new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0,
                    false));
    final JPanel panel2 = new JPanel();
    panel2.setLayout(new GridLayoutManager(2, 2, new Insets(0, 0, 0, 0), -1, -1));
    panel1.add(panel2,
            new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    new Dimension(-1, 100), null, null, 0, false));
    panel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Options"));
    revisionCbx = new JCheckBox();
    revisionCbx.setText("Revision");
    revisionCbx.setMnemonic('R');
    revisionCbx.setDisplayedMnemonicIndex(0);
    panel2.add(revisionCbx,
            new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    revisionTxt = new JTextField();
    revisionTxt.setEnabled(false);
    revisionTxt.setText("tip");
    panel2.add(revisionTxt,
            new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null,
                    new Dimension(150, -1), null, 0, false));
    final Spacer spacer2 = new Spacer();
    panel2.add(spacer2,
            new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1,
                    GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
    final Spacer spacer3 = new Spacer();
    panel2.add(spacer3,
            new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false));
    hgRepositorySelectorComponent = new BzrRepositorySelectorComponent();
    panel1.add(hgRepositorySelectorComponent.$$$getRootComponent$$$(),
            new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null,
                    null, 0, false));
    label1.setLabelFor(repositoryTxt);
}

From source file:com.antelink.sourcesquare.gui.view.ExitSourceSquareView.java

/**
 * Create the frame./*from   w ww.ja v  a 2 s. c  om*/
 */
public ExitSourceSquareView() {
    setIconImage(Toolkit.getDefaultToolkit().getImage(SourceSquareView.class.getResource("/antelink.png")));
    setTitle("SourceSquare");
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 500, 170);
    this.contentPane = new JPanel();
    this.contentPane.setBackground(Color.WHITE);
    this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(this.contentPane);

    this.mainPanel = new JPanel();
    this.mainPanel.setBackground(Color.WHITE);
    GroupLayout gl_contentPane = new GroupLayout(this.contentPane);
    gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addComponent(this.mainPanel, GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE));
    gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
            .addComponent(this.mainPanel, GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE));
    this.mainPanel.setLayout(new BoxLayout(this.mainPanel, BoxLayout.Y_AXIS));

    JPanel panel_1 = new JPanel();
    panel_1.setBackground(Color.WHITE);
    this.mainPanel.add(panel_1);
    panel_1.setLayout(new BorderLayout(0, 0));

    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 20));
    panel.setBackground(Color.WHITE);
    panel_1.add(panel, BorderLayout.SOUTH);

    Image openButtonImage = Toolkit.getDefaultToolkit()
            .getImage(SourceSquareView.class.getResource("/OpenButton.png"));
    this.openButtonLabel = new JLabel(new ImageIcon(openButtonImage));
    this.openButtonLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    panel.add(this.openButtonLabel);

    JLabel exitLabel = new JLabel("<html><b>Closing this window will quit the application</b></html>");
    exitLabel.setFont(new Font("Helvetica", Font.PLAIN, 13));

    JLabel explainLabel = new JLabel("<html>(You won't be able to see or publish your results anymore)</html>");
    explainLabel.setFont(new Font("Helvetica", Font.PLAIN, 13));

    JPanel textPanel = new JPanel();
    textPanel.setBackground(Color.WHITE);
    textPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 0));

    textPanel.add(exitLabel, BorderLayout.CENTER);
    textPanel.add(explainLabel, BorderLayout.CENTER);

    panel_1.add(textPanel, BorderLayout.CENTER);

    CopyrightPanel copyrightPanel = new CopyrightPanel();
    copyrightPanel.setBackground(Color.WHITE);
    this.mainPanel.add(copyrightPanel);
    this.contentPane.setLayout(gl_contentPane);

    setLocationRelativeTo(null);
}

From source file:gov.nih.nci.nbia.StandaloneDM.java

private JPanel constructLoginPanel() {
    JPanel contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(null);

    JLabel lblNewLabel_2 = new JLabel();
    lblNewLabel_2.setBounds(20, 11, 100, 100);
    contentPane.add(lblNewLabel_2);//from   ww w .j a  v a  2  s.  c om
    ImageIcon iconLogo = new ImageIcon("Images/global.logo");
    lblNewLabel_2.setIcon(iconLogo);
    statusLbl = new JLabel(
            "<html>Some or all of the images you are about to download are from<br>private collection(s). Please log in first.</html>");
    contentPane.add(statusLbl);
    statusLbl.setBounds(110, 11, 500, 42);
    JLabel lblNewLabel = new JLabel("User Name");
    contentPane.add(lblNewLabel);
    lblNewLabel.setBounds(110, 79, 77, 31);

    userNameFld = new JTextField();
    contentPane.add(userNameFld);
    userNameFld.setBounds(187, 75, 333, 36);
    userNameFld.setColumns(10);

    JButton submitBtn = new JButton(SubmitBtnLbl);
    submitBtn.addActionListener(new BtnListener());
    contentPane.add(submitBtn);
    submitBtn.setBounds(249, 200, 139, 36);

    passwdFld = new JPasswordField();
    contentPane.add(passwdFld);
    passwdFld.setBounds(187, 129, 333, 36);

    userNameFld.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            passwdFld.requestFocus();
        }
    });

    passwdFld.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            userId = userNameFld.getText();
            password = passwdFld.getText();
            if ((userId.length() < 1) || (password.length() < 1)) {
                statusLbl.setText("Please enter a valid user name and password.");
                statusLbl.setForeground(Color.red);
            } else
                submitUserCredential(userId, password);
        }
    });

    JLabel lblNewLabel_1 = new JLabel("Password");
    contentPane.add(lblNewLabel_1);
    lblNewLabel_1.setBounds(110, 129, 77, 36);

    return contentPane;
}

From source file:net.sf.mpaxs.test.DistributedRmiExecution.java

@Override
public Double call() throws Exception {
    /*//from www. j a v  a  2s.c o m
     * Compute Server is only required for VM external execution
     */
    Impaxs impxs = ComputeServerFactory.getComputeServer();
    if (cfg.getBoolean(ConfigurationKeys.KEY_GUI_MODE, false)) {
        final JFrame jf = new JFrame();
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel controlPanel = new JPanel();
        jf.add(controlPanel);
        controlPanel.setLayout(new BorderLayout());
        impxs.startMasterServer(cfg, controlPanel);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                jf.setVisible(true);
                jf.pack();
            }
        });
    } else {
        impxs.startMasterServer(cfg);
    }
    CompletionServiceFactory<Double> csf = new CompletionServiceFactory<Double>();
    csf.setBlockingWait(true);
    final ICompletionService<Double> mcs = csf.asResubmissionService(csf.newDistributedCompletionService(), 3);
    for (int i = 0; i < maxJobs; i++) {
        mcs.submit(new TestCallable());
    }
    Job<Boolean> job = new Job<Boolean>(new TestScheduledRunnable(), Boolean.TRUE);
    //increase the priority so that the job can bypass other, waiting jobs
    job.setPriority(job.getPriority() + 1);
    //api submission, this job will be wrapped as a ScheduledJob
    impxs.submitScheduledJob(job, 1, 5, TimeUnit.SECONDS);
    //alternative, direct creation of a ScheduledJob
    //      impxs.submitJob(new ScheduledJob(job, 1, 5, TimeUnit.SECONDS));
    double result = 0.0d;
    try {
        List<Double> results = mcs.call();
        System.out.println("Distributed execution: " + results);
        for (Double double1 : results) {
            result += double1;
        }
    } catch (Exception ex) {
        Logger.getLogger(DistributedRmiExecution.class.getName()).log(Level.SEVERE, null, ex);
        throw ex;
    }

    CompletionServiceFactory<String> csf2 = new CompletionServiceFactory<String>();
    //        csf2.setTimeOut(1);
    //        csf2.setTimeUnit(TimeUnit.SECONDS);
    csf2.setBlockingWait(true);
    final ICompletionService<String> mcs2 = csf2.newDistributedCompletionService();
    for (int i = 0; i < maxJobs; i++) {
        mcs2.submit(new TestCallable2());
    }
    try {
        List<String> results = mcs2.call();
        System.out.println("Distributed execution: " + results);
        for (String str : results) {
            System.out.println("Result: " + str);
        }
    } catch (Exception ex) {
        Logger.getLogger(DistributedRmiExecution.class.getName()).log(Level.SEVERE, null, ex);
        throw ex;
    }

    final ICompletionService<Double> mcs3 = csf.newDistributedCompletionService();
    for (int i = 0; i < maxJobs; i++) {
        mcs3.submit(new TestCallable());
    }
    try {
        List<Double> results = mcs3.call();
        System.out.println("Distributed execution: " + results);
        for (Double double1 : results) {
            result += double1;
        }
    } catch (Exception ex) {
        Logger.getLogger(DistributedRmiExecution.class.getName()).log(Level.SEVERE, null, ex);
        throw ex;
    }

    impxs.stopMasterServer();
    return result;
}

From source file:ch.unibas.fittingwizard.application.Visualization.java

public void show(File xyzFile) {
    if (jmolWindow == null) {
        logger.info("Creating Jmol window.");
        jmolWindow = new JFrame("Visualization of " + xyzFile.getName());
        jmolWindow.addWindowListener(new WindowAdapter() {
            @Override/*from  ww  w .  ja  va 2s .  c  om*/
            public void windowClosing(WindowEvent e) {
                logger.info("Jmol window closing.");
                jmolWindow = null;
                jmolViewer = null;
                currentOpenFile = null;
            }
        });
        jmolWindow.setSize(600, 600);

        Container contentPane = jmolWindow.getContentPane();
        JmolPanel jmolPanel = new JmolPanel();

        // main panel -- Jmol panel on top
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(jmolPanel);
        contentPane.add(panel);
        jmolViewer = jmolPanel.viewer;

        alignWindowPositionToWizard();
        jmolWindow.setVisible(true);
    } else {
        logger.debug("Bringing existing Jmol window to front.");
    }
    openFile(xyzFile.getAbsoluteFile());
    jmolWindow.toFront();
}

From source file:Accounts.java

private void buildGUI() {
    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    accountNumberList = new JList();
    loadAccounts();/*  w  ww. j a v  a  2s .co  m*/
    accountNumberList.setVisibleRowCount(2);
    JScrollPane accountNumberListScrollPane = new JScrollPane(accountNumberList);

    //Do Get Account Button
    getAccountButton = new JButton("Get Account");
    getAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                ResultSet rs = statement.executeQuery(
                        "SELECT * FROM acc_acc WHERE acc_id = " + accountNumberList.getSelectedValue());
                if (rs.next()) {
                    accountIDText.setText(rs.getString("acc_id"));
                    usernameText.setText(rs.getString("username"));
                    passwordText.setText(rs.getString("password"));
                    tsText.setText(rs.getString("ts"));
                    activeTSText.setText(rs.getString("act_ts"));
                }
            } catch (SQLException selectException) {
                displaySQLErrors(selectException);
            }
        }
    });

    //Do Insert Account Button
    insertAccountButton = new JButton("Insert Account");
    insertAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate("INSERT INTO acc_acc VALUES(" + accountIDText.getText() + ", "
                        + "'" + usernameText.getText() + "', " + "'" + passwordText.getText() + "', " + "0"
                        + ", " + "now())");
                errorText.append("Inserted " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Delete Account Button
    deleteAccountButton = new JButton("Delete Account");
    deleteAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate(
                        "DELETE FROM acc_acc WHERE acc_id = " + accountNumberList.getSelectedValue());
                errorText.append("Deleted " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    //Do Update Account Button
    updateAccountButton = new JButton("Update Account");
    updateAccountButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Statement statement = connection.createStatement();
                int i = statement.executeUpdate("UPDATE acc_acc " + "SET username='" + usernameText.getText()
                        + "', " + "password='" + passwordText.getText() + "', " + "act_ts = now() "
                        + "WHERE acc_id = " + accountNumberList.getSelectedValue());
                errorText.append("Updated " + i + " rows successfully");
                accountNumberList.removeAll();
                loadAccounts();
            } catch (SQLException insertException) {
                displaySQLErrors(insertException);
            }
        }
    });

    JPanel first = new JPanel(new GridLayout(5, 1));
    first.add(accountNumberListScrollPane);
    first.add(getAccountButton);
    first.add(insertAccountButton);
    first.add(deleteAccountButton);
    first.add(updateAccountButton);

    accountIDText = new JTextField(15);
    usernameText = new JTextField(15);
    passwordText = new JTextField(15);
    tsText = new JTextField(15);
    activeTSText = new JTextField(15);
    errorText = new JTextArea(5, 15);
    errorText.setEditable(false);

    JPanel second = new JPanel();
    second.setLayout(new GridLayout(6, 1));
    second.add(accountIDText);
    second.add(usernameText);
    second.add(passwordText);
    second.add(tsText);
    second.add(activeTSText);

    JPanel third = new JPanel();
    third.add(new JScrollPane(errorText));

    c.add(first);
    c.add(second);
    c.add(third);
    setSize(500, 500);
    show();
}

From source file:com.devoteam.srit.xmlloader.core.report.derived.StatFlow.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.add(new JLabel(
            Utils.formatdouble((this.counter.globalDataset.getValue() * 1000 / this.reportEndTimestamp))
                    + "/s"));

    panel.setToolTipText(generateRTStatsToolTip());

    addMouseListenerForGraph(panel);/*from  w  w  w.  j a va  2 s  . com*/

    return panel;
}