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.digitalgeneralists.assurance.ui.components.ExclusionsPanel.java

@Override
protected void initializeComponent() {
    if (!this.initialized) {
        if (this.exclusion == null) {
            this.mode = AssuranceDialogMode.ADD;
            this.dialogTitle = "Add New Exclusion";
            this.exclusion = new FileReference();
        } else {/*from   ww w  . ja v  a2 s. c o m*/
            this.mode = AssuranceDialogMode.EDIT;
            this.dialogTitle = "Edit Exclusion";
        }

        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        final JPanel exclusionPathPanel = new JPanel();
        exclusionPathPanel.setLayout(new GridBagLayout());

        Border exclusionPanelBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
        exclusionPanelBorder = BorderFactory.createTitledBorder(exclusionPanelBorder, "Exclusion",
                TitledBorder.CENTER, TitledBorder.TOP);

        GridBagConstraints exclusionPathPanelConstraints = new GridBagConstraints();
        exclusionPathPanelConstraints.anchor = GridBagConstraints.NORTH;
        exclusionPathPanelConstraints.fill = GridBagConstraints.HORIZONTAL;
        exclusionPathPanelConstraints.gridx = 0;
        exclusionPathPanelConstraints.gridy = 0;
        exclusionPathPanelConstraints.weightx = 1.0;
        exclusionPathPanelConstraints.weighty = 1.0;
        exclusionPathPanelConstraints.gridheight = 1;
        exclusionPathPanelConstraints.gridwidth = 2;
        exclusionPathPanelConstraints.insets = new Insets(5, 5, 5, 5);

        exclusionPathPanel.setBorder(exclusionPanelBorder);
        this.add(exclusionPathPanel, exclusionPathPanelConstraints);

        GridBagConstraints exclusionPathFieldConstraints = new GridBagConstraints();
        exclusionPathFieldConstraints.anchor = GridBagConstraints.NORTH;
        exclusionPathFieldConstraints.fill = GridBagConstraints.HORIZONTAL;
        exclusionPathFieldConstraints.gridx = 0;
        exclusionPathFieldConstraints.gridy = 1;
        exclusionPathFieldConstraints.weightx = 1.0;
        exclusionPathFieldConstraints.weighty = 1.0;
        exclusionPathFieldConstraints.gridheight = 1;
        exclusionPathFieldConstraints.gridwidth = 1;
        exclusionPathFieldConstraints.insets = new Insets(5, 5, 5, 5);

        exclusionPathPanel.add(this.exclusionPathTextFieldPicker, exclusionPathFieldConstraints);

        if (this.exclusion != null) {
            File exclusionPath = exclusion.getFile();
            if (exclusionPath != null) {
                this.exclusionPathTextFieldPicker.setValue(exclusionPath.getPath());
            } else {
                this.exclusionPathTextFieldPicker.setValue("");
            }
        }

        this.initialized = true;
    }
}

From source file:com.floreantpos.config.ui.AddPrinterGroupDialog.java

private void init() {
    JPanel contentPane = (JPanel) getContentPane();
    contentPane.setLayout(new MigLayout("", "[][grow]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    add(new JLabel(Messages.getString("AddPrinterGroupDialog.4"))); //$NON-NLS-1$
    add(tfName, "grow, wrap"); //$NON-NLS-1$

    chkDefault = new JCheckBox(Messages.getString("AddPrinterGroupDialog.1")); //$NON-NLS-1$

    add(new JLabel(), "grow"); //$NON-NLS-1$
    add(chkDefault, "wrap"); //$NON-NLS-1$

    PosPrinters printersKitchen = PosPrinters.load();
    printers = printersKitchen.getKitchenPrinters();
    printerList = new CheckBoxList(new Vector<Printer>(printers));

    JPanel listPanel = new JPanel(new BorderLayout());
    listPanel.setBorder(new TitledBorder(Messages.getString("AddPrinterGroupDialog.6"))); //$NON-NLS-1$
    listPanel.add(new JScrollPane(printerList));

    add(listPanel, "newline, span 2, grow"); //$NON-NLS-1$

    JPanel panel = new JPanel();
    contentPane.add(panel, "cell 0 4 3 1,grow"); //$NON-NLS-1$

    JButton btnOk = new JButton(Messages.getString("AddPrinterGroupDialog.9")); //$NON-NLS-1$
    btnOk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (StringUtils.isEmpty(tfName.getText())) {
                POSMessageDialog.showError(Application.getPosWindow(),
                        Messages.getString("AddPrinterGroupDialog.10")); //$NON-NLS-1$
                return;
            }//from   w  w  w  .j av a  2s . c  o m

            List checkedValues = printerList.getCheckedValues();
            if (checkedValues == null || checkedValues.size() == 0) {
                POSMessageDialog.showError(Application.getPosWindow(),
                        Messages.getString("AddPrinterGroupDialog.11")); //$NON-NLS-1$
                return;
            }

            setCanceled(false);
            dispose();
        }
    });
    panel.add(btnOk);

    JButton btnCancel = new JButton(Messages.getString("AddPrinterGroupDialog.12")); //$NON-NLS-1$
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setCanceled(true);
            dispose();
        }
    });
    panel.add(btnCancel);
}

From source file:customprogressindicator.CustomProgress.java

private JPanel createComponents() {
    JPanel top = new JPanel();
    top.setBackground(Color.WHITE);
    top.setLayout(new BorderLayout(20, 20));

    // get applet parameter using an instance of the AppletStub class
    // "tagLine" parameter specified in applet's JNLP file
    String tagLine = "";
    if (appletStub != null) {
        tagLine = appletStub.getParameter("tagLine");
    }//from   w  w w. ja va  2  s  .co  m
    String lblText = "<html><font color=red size=+2>JDK Documentation</font><br/>" + tagLine + " <br/></html>";
    JLabel lbl = new JLabel(lblText);
    top.add(lbl, BorderLayout.NORTH);

    // use JSObject.getWindow(null) method to retrieve a reference to
    // the web page and make JavaScript calls. Duke logo displayed if
    // displayLogo variable set to "true" in the web page
    String displayLogo = "false";
    JSObject window = JSObject.getWindow(null);
    if (window != null) {
        displayLogo = (String) window.getMember("displayLogo");
    }
    if (displayLogo.equals("true")) {
        lbl = new JLabel();
        ImageIcon logo = createImageIcon("images/DukeWave.gif", "logo");
        lbl.setIcon(logo);
        top.add(lbl, BorderLayout.EAST);
    }

    statusLabel = new JLabel("<html><font color=green size=-2>Loading applet...</font></html>");
    top.add(statusLabel, BorderLayout.CENTER);

    progressBar = new JProgressBar(0, 100);
    progressBar.setValue(0);
    progressBar.setStringPainted(true);
    top.add(progressBar, BorderLayout.SOUTH);

    return top;
}

From source file:com.codecrate.shard.ui.view.CharacterManagerView.java

protected JComponent createControl() {
    JPanel view = new JPanel();
    view.setLayout(new BorderLayout());
    view.add(getTabbedPane(), BorderLayout.CENTER);
    return view;//from   ww w.  j a v  a2 s  .  c  o  m
}

From source file:com.eviware.soapui.impl.rest.panels.mock.RestMockResponseDesktopPanel.java

private JComponent createMediaTypeCombo() {
    MediaTypeComboBox mediaTypeComboBox = new MediaTypeComboBox(this.getModelItem());
    mediaTypeComboBox.addItemListener(new ItemListener() {
        @Override/*from   ww  w  .  j  av  a 2 s.  com*/
        public void itemStateChanged(ItemEvent e) {
            setMediaType(getResponseEditor().getInputArea(), e.getItem().toString());
        }
    });
    JComponent innerPanel = createPanelWithLabel("Content | Media type: ", mediaTypeComboBox);

    JPanel outerPanel = new JPanel();
    outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.X_AXIS));
    outerPanel.add(innerPanel);
    outerPanel.add(Box.createHorizontalGlue());
    outerPanel
            .add(UISupport.createFormButton(new ShowOnlineHelpAction(HelpUrls.REST_MOCK_RESPONSE_EDITOR_BODY)));

    return outerPanel;
}

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

/**
 * Constructor.//from   w  ww . jav a  2  s .co  m
 */
public NewRdfModelJDialog() {

    super(Messages.getString("NewRdfModelJDialog.title"));

    JPanel framePanel = new JPanel();
    framePanel.setLayout(new GridLayout(3, 1));

    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    p.add(new JLabel(Messages.getString("NewRdfModelJDialog.subject")));

    subjectNs = new JTextField(30);
    subjectNs.setText(MindRaiderConstants.MR_RDF_PREDICATE_NS);
    p.add(subjectNs);
    p.add(new JLabel("#"));

    subjectLocalName = new JTextField(15);
    p.add(subjectLocalName);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.RIGHT));
    final JCheckBox literalCheckBox = new JCheckBox("literal", false);
    p.add(literalCheckBox);
    framePanel.add(p);

    p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton addButton = new JButton(Messages.getString("NewRdfModelJDialog.create"));
    p.add(addButton);
    addButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            createModel(literalCheckBox);
        }
    });

    JButton cancelButton = new JButton(Messages.getString("NewRdfModelJDialog.cancel"));
    p.add(cancelButton);
    cancelButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            NewRdfModelJDialog.this.dispose();
        }
    });
    framePanel.add(p);

    subjectLocalName.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                createModel(literalCheckBox);
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });

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

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

    addWindowListener(new WindowAdapter() {

        public void windowActivated(WindowEvent e) {
            subjectLocalName.requestFocusInWindow();
        }
    });
}

From source file:com.stefanbrenner.droplet.ui.AddDeviceDialog.java

public AddDeviceDialog(final JFrame frame, final IDropletContext dropletContext) {
    super(frame, dropletContext, Messages.getString("AddDeviceDialog.title")); //$NON-NLS-1$

    droplet = dropletContext.getDroplet();

    JPanel panel = new JPanel();

    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    panel.setLayout(new GridLayout(1, 0, 7, 7));

    btnValve = new JButton(Messages.getString("AddDeviceDialog.valve")); //$NON-NLS-1$
    btnValve.addActionListener(this);
    panel.add(btnValve);//from  w  w w  .ja v a 2  s  .c  om
    btnFlash = new JButton(Messages.getString("AddDeviceDialog.flash")); //$NON-NLS-1$
    btnFlash.addActionListener(this);
    panel.add(btnFlash);
    btnCamera = new JButton(Messages.getString("AddDeviceDialog.camera")); //$NON-NLS-1$
    btnCamera.addActionListener(this);
    panel.add(btnCamera);
    btnButton = new JButton(Messages.getString("AddDeviceDialog.button")); //$NON-NLS-1$
    btnButton.addActionListener(this);
    panel.add(btnButton);
    btnClose = new JButton(Messages.getString("AddDeviceDialog.close")); //$NON-NLS-1$
    btnClose.addActionListener(this);
    panel.add(btnClose);

    add(panel);

    setAlwaysOnTop(true);
    setResizable(false);
    pack();
    setLocationRelativeTo(frame);

    droplet.addPropertyChangeListener(IDroplet.ASSOCIATION_DEVICES, new PropertyChangeListener() {
        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            updateComponents();
        }
    });
    updateComponents();

}

From source file:SimpleDateFormatDemo.java

public SimpleDateFormatDemo() {

    today = new Date();
    availableLocales = new LocaleGroup();

    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:");
    patternLabel1.setAlignmentX(Component.LEFT_ALIGNMENT);
    patternLabel2.setAlignmentX(Component.LEFT_ALIGNMENT);

    JComboBox patternList = new JComboBox(patternExamples);
    patternList.setSelectedIndex(0);// w w  w .  j  ava 2  s . co  m
    patternList.setEditable(true);
    patternList.setAlignmentX(Component.LEFT_ALIGNMENT);
    PatternListener patternListener = new PatternListener();
    patternList.addActionListener(patternListener);

    // Set up the UI for selecting a locale.
    JLabel localeLabel = new JLabel("Select a Locale from the list:");
    localeLabel.setAlignmentX(Component.LEFT_ALIGNMENT);

    JComboBox localeList = new JComboBox(availableLocales.getStrings());
    localeList.setSelectedIndex(0);
    localeList.setAlignmentX(Component.LEFT_ALIGNMENT);
    LocaleListener localeListener = new LocaleListener();
    localeList.addActionListener(localeListener);

    // Create the UI for displaying result
    JLabel resultLabel = new JLabel("Current Date and Time", JLabel.LEFT);
    resultLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    result = new JLabel(" ");
    result.setForeground(Color.black);
    result.setAlignmentX(Component.LEFT_ALIGNMENT);
    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.Y_AXIS));
    patternPanel.add(patternLabel1);
    patternPanel.add(patternLabel2);
    patternPanel.add(patternList);

    JPanel localePanel = new JPanel();
    localePanel.setLayout(new BoxLayout(localePanel, BoxLayout.Y_AXIS));
    localePanel.add(localeLabel);
    localePanel.add(localeList);

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

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    patternPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    localePanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    resultPanel.setAlignmentX(Component.CENTER_ALIGNMENT);

    add(patternPanel);
    add(Box.createVerticalStrut(10));
    add(localePanel);
    add(Box.createVerticalStrut(10));
    add(resultPanel);

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

    reformat();

}

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

public FtsJDialog() {
    super(Messages.getString("FtsJDialog.title"));

    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./*from   w  w  w  .  j av a  2 s  .  co m*/
    // TODO add help like in eclipse
    contentPanel.add(new JLabel(Messages.getString("FtsJDialog.searchString")), BorderLayout.NORTH);
    // 1b.
    String[] knownSearches = new String[] { "", "RDF", "mind", "concept", "China" };
    ftsCombo = new JComboBox(knownSearches);
    ftsCombo.setPreferredSize(new Dimension(200, 18));
    ftsCombo.setEditable(true);
    ftsCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if ("comboBoxEdited".equals(e.getActionCommand())) {
                search();
            }
        }
    });
    contentPanel.add(ftsCombo, 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:de.codesourcery.eve.skills.ui.components.impl.PasswordComponent.java

@Override
protected JPanel createPanelHook() {

    final JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());

    int y = 0;//ww  w.  j  a  va 2 s.  c  o  m
    if (!StringUtils.isBlank(message)) {
        panel.add(new JLabel(message), constraints(0, y++).width(2).end());
    }

    password1.setColumns(10);
    password2.setColumns(10);

    switch (mode) {
    case SET_PASSWORD:

        panel.add(new JLabel("Enter new password:"), constraints(0, y).end());
        panel.add(password1, constraints(1, y++).end());

        panel.add(new JLabel("Confirm password:"), constraints(0, y).end());
        panel.add(password2, constraints(1, y++).end());

        break;
    case QUERY_PASSWORD:
        panel.add(new JLabel("Enter password:"), constraints(0, y).end());
        panel.add(password1, constraints(1, y++).end());
        break;
    default:
        throw new RuntimeException("Unreachable code reached");
    }

    panel.add(this.savePassword, constraints(0, y).anchorEast().useRemainingWidth().end());
    return panel;
}