Example usage for javax.swing JPanel setPreferredSize

List of usage examples for javax.swing JPanel setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JPanel setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:org.ecoinformatics.seek.ecogrid.CheckBoxTableCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    jTable = table;//from   w w w . ja v  a  2s. c  o m

    JPanel cellPanel = new JPanel();
    cellPanel.setBorder(new LineBorder(Color.lightGray, 1));
    cellPanel.setBackground(Color.WHITE);
    cellPanel.setPreferredSize(
            new Dimension(ServicesDisplayPanel.CELLPREFERREDWIDTH, ServicesDisplayPanel.HEIGHT));

    SelectableDocumentType selectedDocumentType = null;
    boolean isChecked = false;
    boolean isEnable = true;
    String text = null;
    if (value != null && value instanceof SelectableObjectInterface) {
        SelectableObjectInterface selectedObj = (SelectableObjectInterface) value;
        text = selectedObj.getSelectableObjectLabel();
        isChecked = selectedObj.getIsSelected();
        isEnable = selectedObj.getEnabled();
    }

    /*
     * label = (JLabel)renderer.getTableCellRendererComponent(table, text,
     * isSelected, hasFocus, row, column);
     */
    JLabel label = new JLabel(text);
    label.setFont(new Font(FONTNAME, Font.PLAIN, FONTSIZE));
    label.setPreferredSize(new Dimension(ServicesDisplayPanel.LABELPREFERWIDTH, ServicesDisplayPanel.HEIGHT));
    // set a check box name
    String checkBoxName = "" + topRowNum + SEPERATOR + row;
    JCheckBox checkBox = new JCheckBox();
    checkBox.setName(checkBoxName);
    checkBox.setBackground(Color.WHITE);
    checkBox.setSelected(isChecked);
    CheckBoxListener listener = new CheckBoxListener();
    checkBox.addItemListener(listener);
    // checkBox.setEnabled(false);

    /*
     * if (topRowNum != DEFAUTTOPROW ) { // for sub table we need to set up
     * check box enable status checkBox.setEnabled(isEnable); }//if
     */

    // add the label and checkbox to jpanel which has a border layout
    // manager
    BorderLayout layoutManager = new BorderLayout();
    cellPanel.setLayout(layoutManager);
    cellPanel.add(label, BorderLayout.CENTER);
    cellPanel.add(checkBox, BorderLayout.WEST);
    return cellPanel;
}

From source file:org.executequery.gui.editor.LobDataItemViewerPanel.java

private void init() {

    Border emptyBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2);

    JPanel textPanel = new JPanel(new BorderLayout());
    textPanel.setBorder(emptyBorder);/*ww w . ja  v  a2s  .c  o m*/

    textArea = createTextArea();
    textArea.setLineWrap(false);
    textArea.setMargin(new Insets(2, 2, 2, 2));
    textPanel.add(new JScrollPane(textArea), BorderLayout.CENTER);

    JPanel imagePanel = null;

    imagePanel = new JPanel(new BorderLayout());
    imagePanel.setBorder(emptyBorder);

    if (isImage()) {

        ImageIcon image = loadImageData();
        if (image != null) {

            JLabel imageLabel = new JLabel(image);
            imagePanel.add(new JScrollPane(imageLabel), BorderLayout.CENTER);
        }

        setTextAreaText(textArea, CANNOT_DISPLAY_BINARY_DATA_AS_TEXT);

    } else {

        imagePanel.add(new JLabel("Unsupported format", JLabel.CENTER));

        loadTextData();
    }

    JPanel binaryPanel = new JPanel(new BorderLayout());
    binaryPanel.setBorder(emptyBorder);

    binaryStringTextArea = createTextArea();
    binaryPanel.add(new JScrollPane(binaryStringTextArea), BorderLayout.CENTER);

    tabbedPane = new JTabbedPane();
    tabbedPane.addChangeListener(this);
    tabbedPane.addTab("Text", textPanel);
    tabbedPane.addTab("Image", imagePanel);
    tabbedPane.addTab("Binary", binaryPanel);

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.setPreferredSize(new Dimension(400, 300));
    contentPanel.add(tabbedPane, BorderLayout.CENTER);

    JLabel descriptionLabel = new JLabel(formatDescriptionString());
    descriptionLabel.setBorder(BorderFactory.createEmptyBorder(5, 2, 5, 0));

    contentPanel.add(descriptionLabel, BorderLayout.SOUTH);

    JButton closeButton = new JButton("Close");
    closeButton.setActionCommand("close");

    JButton saveButton = new JButton("Save As");
    saveButton.setActionCommand("save");

    saveButton.addActionListener(this);
    closeButton.addActionListener(this);

    addActionButton(saveButton);
    addActionButton(closeButton);

    setPreferredSize(new Dimension(500, 420));

    addContentPanel(contentPanel);

    textArea.requestFocus();
}

From source file:org.isatools.isacreatorconfigurator.ontologyconfigurationtool.OntologyConfigUI.java

private void setOntologySelectionPanelPlaceholder(ImageIcon image) {
    JPanel placeHolder = new JPanel(new GridLayout(1, 1));
    placeHolder.add(new JLabel(image, SwingConstants.CENTER));
    placeHolder.setPreferredSize(new Dimension(500, 300));
    ontologyViewContainer.removeAll();//from w  w  w.  j  av a  2 s .com
    ontologyViewContainer.add(placeHolder);
    ontologyViewContainer.revalidate();
    ontologyViewContainer.repaint();
}

From source file:org.jas.dnd.DragTooltipDialog.java

private DynamicPanel getDynamicPanel(IconType type, List<?> list) {
    if (list == null || list.isEmpty()) {
        return null;
    }/*www .ja  va  2 s .co m*/

    JPanel dynamicPanel = null;
    JLabel dynamicText = null;

    String text = list.isEmpty() ? null : (list.size()) + " " + (type == null ? "ERROR" : type.getText());
    if (list.size() == 1) {
        text = list.get(0) instanceof File ? ((File) list.get(0)).getName() : list.get(0).toString();
    }

    dynamicText = new JLabel(text);
    dynamicText.setForeground(Color.WHITE);
    FontMetrics fontMetrics = dynamicText.getFontMetrics(dynamicText.getFont());
    int width = fontMetrics.stringWidth(dynamicText.getText()) + DEFAULT_MIN_FONT_WIDTH;
    int realHeight = ROW_HEIGHT;
    String longestText = "";
    while (text.contains("<br>")) {
        text = text.substring(text.indexOf("<br>") + DEFAULT_MIN_FONT_WIDTH);
        if (text.length() > longestText.length()) {
            longestText = text;
        }
        realHeight += ROW_HEIGHT;
    }
    if (!longestText.isEmpty()) {
        width = fontMetrics.stringWidth(longestText) + DEFAULT_MIN_FONT_WIDTH;
    }
    dynamicPanel = new JPanel();
    dynamicPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    dynamicPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, realHeight));
    dynamicPanel.setMinimumSize(new Dimension(0, realHeight));
    dynamicPanel.setPreferredSize(new Dimension(100, realHeight));
    dynamicPanel.setSize(new Dimension(100, realHeight));
    if (type != null) {
        dynamicPanel.add(getDynamicIcon(type), null);
        JPanel spacer = new JPanel();
        Dimension d = new Dimension(SPACER_WIDTH, SPACER_WIDTH);
        width += SPACER_WIDTH;

        spacer.setSize(d);
        spacer.setMinimumSize(d);
        spacer.setMaximumSize(d);
        spacer.setPreferredSize(d);
        dynamicPanel.add(spacer);
        width += type.width;
    }
    dynamicPanel.add(dynamicText);
    return new DynamicPanel(dynamicPanel, width, realHeight);
}

From source file:org.jas.dnd.DragTooltipDialog.java

private JPanel getDynamicIcon(IconType type) {
    JPanel dynamicIcon = null;
    dynamicIcon = new JPanel();
    dynamicIcon.setMaximumSize(new Dimension(type.width, type.height));
    dynamicIcon.setPreferredSize(new Dimension(type.width, type.height));
    dynamicIcon.setName(type.synthName);
    dynamicIcon.setMinimumSize(new Dimension(type.width, type.height));
    return dynamicIcon;
}

From source file:org.lnicholls.galleon.gui.MainFrame.java

protected JComponent createContentPane() {

    JPanel panel = new JPanel(new BorderLayout());

    mOptionsPanelManager = new OptionsPanelManager(this);

    mOptionsPanelManager.setMinimumSize(new Dimension(200, 100));

    mOptionsPanelManager.setPreferredSize(new Dimension(400, 250));

    InternalFrame navigator = new InternalFrame("Apps");

    mAppTree = new AppTree(this, getAppsModel());

    navigator.setContent(createScrollPane(mAppTree));

    navigator.setSelected(true);//from  ww  w.j a v a  2  s. c  om

    navigator.setMinimumSize(new Dimension(100, 100));

    navigator.setPreferredSize(new Dimension(150, 400));

    JSplitPane mainSplitPane = createSplitPane(1, navigator, mOptionsPanelManager, 0.25D);

    mainSplitPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    panel.add(mainSplitPane, "Center");

    JLabel statusField = new JLabel("Copyright \251 2005, 2006 Leon Nicholls");

    statusField.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel statusPanel = new JPanel(new BorderLayout());

    statusPanel.add(statusField, "West");

    panel.add(statusPanel, "South");

    panel.setPreferredSize(new Dimension(700, 450));

    return panel;

}

From source file:org.monome.pages.AbletonClipSkipperPage.java

public JPanel getPanel() {
    if (this.panel != null) {
        return this.panel;
    }//  ww  w. j a  v a  2  s .  c  om

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    panel.setPreferredSize(new java.awt.Dimension(464, 156));

    pageNameLBL = new JLabel("Page " + (this.index + 1) + ": Ableton Clip Skipper");
    panel.add(pageNameLBL);

    refreshButton.setText("Refresh from Ableton");
    refreshButton.addActionListener(this);
    panel.add(refreshButton);

    this.panel = panel;
    return panel;
}

From source file:org.monome.pages.ExternalApplicationPage.java

public JPanel getPanel() {
    if (this.panel != null) {
        return this.panel;
    }//from www  . j av  a 2s . co m

    // builds the page GUI
    JPanel panel = new JPanel();
    panel.setLayout(null);
    panel.setPreferredSize(new java.awt.Dimension(220, 180));

    pageNameLBL = new JLabel("Page " + (this.index + 1) + ": " + this.getName());
    prefixLabel = new JLabel();
    prefixLabel.setText("OSC Prefix");
    hostnameLabel = new JLabel();
    hostnameLabel.setText("OSC Hostname");
    oscInLabel = new JLabel();
    oscInLabel.setText("OSC In Port");
    oscOutLabel = new JLabel();
    oscOutLabel.setText("OSC Out Port");
    oscInTF = new JTextField();
    oscInTF.setText(String.valueOf(this.inPort));
    oscOutTF = new JTextField();
    panel.add(oscOutTF);
    panel.add(oscOutLabel);
    panel.add(oscInTF);
    panel.add(oscInLabel);
    oscInLabel.setBounds(12, 65, 85, 14);
    oscInTF.setBounds(97, 62, 100, 21);
    oscOutLabel.setBounds(12, 86, 85, 14);
    oscOutTF.setText(String.valueOf(this.outPort));
    oscOutTF.setBounds(97, 83, 100, 21);
    updatePrefsButton = new JButton();
    updatePrefsButton.setText("Update Preferences");
    updatePrefsButton.addActionListener(this);
    prefixTF = new JTextField();
    prefixTF.setText(this.prefix);
    hostnameTF = new JTextField();
    panel.add(hostnameTF);
    panel.add(hostnameLabel);
    panel.add(prefixTF);
    panel.add(prefixLabel);
    panel.add(pageNameLBL);
    panel.add(updatePrefsButton);
    panel.add(getDisableCache());
    updatePrefsButton.setBounds(12, 140, 169, 21);
    pageNameLBL.setBounds(0, 0, 250, 14);
    prefixLabel.setBounds(12, 23, 85, 14);
    prefixTF.setBounds(97, 20, 100, 21);
    hostnameLabel.setBounds(12, 44, 85, 14);
    hostnameTF.setText(this.hostname);
    hostnameTF.setBounds(97, 41, 100, 21);

    this.panel = panel;
    return panel;
}

From source file:org.monome.pages.MachineDrumInterfacePage.java

public JPanel getPanel() {
    if (this.panel != null) {
        return this.panel;
    }//from w ww  .  j  ava  2s  . c  om

    JPanel panel = new JPanel();
    AnchorLayout panelLayout = new AnchorLayout();
    panel.setLayout(panelLayout);
    panel.setPreferredSize(new java.awt.Dimension(319, 127));
    panel.add(getAddMidiOutButton(), new AnchorConstraint(775, 963, 917, 521, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getUpdatePrefsButton(), new AnchorConstraint(767, 487, 917, 20, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getSpeedTF(), new AnchorConstraint(507, 340, 712, 236, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getSpeedLabel(), new AnchorConstraint(531, 236, 673, 57, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));

    this.getUpdatePrefsButton().addActionListener(this);
    this.getAddMidiOutButton().addActionListener(this);

    pageNameLBL = new JLabel("Page " + (this.index + 1) + ": Machine Drum Interface");
    panel.add(pageNameLBL, new AnchorConstraint(0, 600, 120, 0, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));

    JLabel midiout = new JLabel("MIDI Out: " + this.midiDeviceName);
    panel.add(midiout, new AnchorConstraint(271, 948, 429, 20, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    pageNameLBL.setPreferredSize(new java.awt.Dimension(296, 20));

    this.panel = panel;
    return panel;
}

From source file:org.monome.pages.MIDIFadersPage.java

public JPanel getPanel() {
    if (this.panel != null) {
        return this.panel;
    }//from w  w  w  .j a v a2 s .  c o m
    JPanel panel = new JPanel();
    AnchorLayout panelLayout = new AnchorLayout();
    panel.setLayout(panelLayout);
    panel.setPreferredSize(new java.awt.Dimension(319, 148));
    panel.add(getAddMidiOutButton(), new AnchorConstraint(706, 963, 875, 521, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getUpdatePrefsButton(), new AnchorConstraint(706, 487, 875, 20, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getDelayTF(), new AnchorConstraint(347, 371, 489, 268, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getDelayLabel(), new AnchorConstraint(347, 268, 489, 20, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));

    this.getUpdatePrefsButton().addActionListener(this);
    this.getAddMidiOutButton().addActionListener(this);

    pageNameLBL = new JLabel("Page " + (this.index + 1) + ":  MIDI Faders");
    panel.add(pageNameLBL, new AnchorConstraint(0, 800, 82, 0, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getChannelL(), new AnchorConstraint(347, 710, 489, 500, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getChannelTF(), new AnchorConstraint(354, 813, 483, 710, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getCcOffsetLabel(), new AnchorConstraint(489, 268, 638, 20, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    panel.add(getCcOffsetTF(), new AnchorConstraint(503, 371, 625, 268, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));

    JLabel midiout = new JLabel("MIDI Out: " + this.midiDeviceName);
    panel.add(midiout, new AnchorConstraint(179, 894, 307, 20, AnchorConstraint.ANCHOR_REL,
            AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
    midiout.setPreferredSize(new java.awt.Dimension(279, 19));
    pageNameLBL.setPreferredSize(new java.awt.Dimension(272, 20));

    this.panel = panel;
    return panel;
}