Java Code Examples for javax.swing.JComponent#setMaximumSize()

The following examples show how to use javax.swing.JComponent#setMaximumSize() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
JComponent addComboField(JPanel parent, String labelText, String propertyName, boolean isRequired, boolean isEditable) {
    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor(propertyName);
    propertyDescriptor.setNotEmpty(isRequired);
    PropertyEditor editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent editorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    editorComponent.setMaximumSize(new Dimension(editorComponent.getMaximumSize().width, controlHeight));
    editorComponent.setPreferredSize(new Dimension(editorComponent.getPreferredSize().width, controlHeight));
    if (editorComponent instanceof JComboBox) {
        JComboBox comboBox = (JComboBox)editorComponent;
        comboBox.setEditable(isEditable);
        comboBox.setEnabled(isEditable);
    }
    JLabel jLabel = new JLabel(labelText);
    parent.add(jLabel);
    jLabel.setLabelFor(editorComponent);
    parent.add(editorComponent);
    return editorComponent;
}
 
Example 2
JComponent addTextField(JPanel parent, TextFieldEditor textEditor, String labelText,
                        String propertyName, boolean isRequired, String[] excludedChars) {
    JLabel jLabel = new JLabel(labelText);
    Dimension size = jLabel.getPreferredSize();
    parent.add(jLabel);
    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor(propertyName);
    if (isRequired) {
        propertyDescriptor.setValidator(new DecoratedNotEmptyValidator(jLabel, excludedChars));
        jLabel.setMaximumSize(new Dimension(size.width + 20, size.height));
    }
    JComponent editorComponent = textEditor.createEditorComponent(propertyDescriptor, bindingContext);
    UIUtils.addPromptSupport(editorComponent, "enter " + labelText.toLowerCase().replace(":", "") + " here");
    UIUtils.enableUndoRedo(editorComponent);
    editorComponent.setPreferredSize(new Dimension(editorComponent.getPreferredSize().width, controlHeight));
    editorComponent.setMaximumSize(new Dimension(editorComponent.getMaximumSize().width, controlHeight));
    jLabel.setLabelFor(editorComponent);
    parent.add(editorComponent);
    return editorComponent;
}
 
Example 3
private JComponent label_and_object(String label_name, JComponent object) {
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
	JLabel label = new JLabel(label_name);
	label.setPreferredSize(new Dimension(150, label.getMaximumSize().height));
	panel.add(label);
	object.setMaximumSize(new Dimension(Short.MAX_VALUE, label.getMaximumSize().height * 2));
	panel.add(object);
	return panel;
}
 
Example 4
private JComponent label_and_object(String label_name, JComponent object) {
	JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    JLabel label = new JLabel(label_name);
    label.setPreferredSize(new Dimension(150, label.getMaximumSize().height));
    panel.add(label);
    object.setMaximumSize(new Dimension(Short.MAX_VALUE, label.getMaximumSize().height * 2));
    panel.add(object);
	return panel;
}
 
Example 5
private JComponent label_and_object(String label_name, JComponent object) {
	JPanel panel = new JPanel();
	panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
	JLabel label = new JLabel(label_name);
	label.setPreferredSize(new Dimension(240, label.getMaximumSize().height));
	panel.add(label);
	object.setMaximumSize(new Dimension(Short.MAX_VALUE, label.getMaximumSize().height * 2));
	panel.add(object);
	return panel;
}
 
Example 6
private JComponent label_and_object(String label_name, JComponent object, int height) {
	JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    JLabel label = new JLabel(label_name);
    label.setPreferredSize(new Dimension(150, label.getMaximumSize().height));
    panel.add(label);
    object.setMaximumSize(new Dimension(Short.MAX_VALUE, label.getMaximumSize().height * height));
    panel.add(object);
	return panel;
}
 
Example 7
Source Project: swift-explorer   File: ProxyPanel.java    License: Apache License 2.0 5 votes vote down vote up
private JComponent setMinPrefMaxWidth (JComponent comp, int minPrefW, int maxW)
{
	if (comp == null)
		return null ;
	comp.setMinimumSize(new Dimension(minPrefW, 0));
	comp.setPreferredSize(new Dimension(minPrefW, 25));
	comp.setMaximumSize(new Dimension(maxW, Integer.MAX_VALUE));
	return comp ;
}
 
Example 8
private JComponent label_and_object(String label_name, JComponent object) {
	JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    JLabel label = new JLabel(label_name);
    label.setPreferredSize(new Dimension(150, label.getMaximumSize().height));
    panel.add(label);
    object.setMaximumSize(new Dimension(Short.MAX_VALUE, label.getMaximumSize().height * 2));
    panel.add(object);
	return panel;
}
 
Example 9
Source Project: netbeans   File: CompletionLayoutPopup.java    License: Apache License 2.0 5 votes vote down vote up
/** 
 * Sets maximum size for appropriate JComponent, depending on
 * wheteher additional items are present
 */
private final void setMaxSize(JComponent comp, Dimension maxSize) {
    if (comp instanceof JPanel) {
        comp.getComponent(0).setMaximumSize(maxSize); // JScrollPane
    } else {
        comp.setMaximumSize(maxSize);
    }
}
 
Example 10
@Override
protected JPanel createPreProcessingPanel() {
    final JPanel preProcessingPanel = new JPanel(new SpringLayout());

    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor("preprocessorExternalTool");
    PropertyEditor editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent editorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    editorComponent.setMaximumSize(new Dimension(editorComponent.getMaximumSize().width, controlHeight));
    editorComponent.setPreferredSize(new Dimension(editorComponent.getPreferredSize().width, controlHeight));

    preProcessingPanel.add(createCheckboxComponent("preprocessTool", editorComponent, newOperatorDescriptor.getPreprocessTool()));
    preProcessingPanel.add(new JLabel(Bundle.CTL_Label_PreprocessingTool_Text()));
    preProcessingPanel.add(editorComponent);

    propertyDescriptor = propertyContainer.getDescriptor("processingWriter");
    editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    editorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    editorComponent.setMaximumSize(new Dimension(editorComponent.getMaximumSize().width, controlHeight));
    editorComponent.setPreferredSize(new Dimension(editorComponent.getPreferredSize().width, controlHeight));

    JComponent writeComponent = createCheckboxComponent("writeForProcessing", editorComponent, newOperatorDescriptor.shouldWriteBeforeProcessing());

    preProcessingPanel.add(writeComponent);
    preProcessingPanel.add(new JLabel(Bundle.CTL_Label_WriteBefore_Text()));
    preProcessingPanel.add(editorComponent);

    TitledBorder title = BorderFactory.createTitledBorder(Bundle.CTL_Panel_PreProcessing_Border_TitleText());
    preProcessingPanel.setBorder(title);

    SpringUtilities.makeCompactGrid(preProcessingPanel, 2, 3, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    return preProcessingPanel;
}
 
Example 11
public JLabelled(String text, String tooltip, JComponent main, int labelWidth)
{
  // This panel is horizontal box.
  setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
  setAlignmentX(Component.LEFT_ALIGNMENT);

  // Shorten text to last part after a dot
  // if it's too long
  final FontMetrics fm = main.getFontMetrics(main.getFont());
  if (fm != null) {
    int ix;
    while (-1 != (ix = text.indexOf("."))
           && fm.stringWidth(text) > labelWidth) {
      text = text.substring(ix + 1);
    }
  }

  final JLabel label = new JLabel(text);
  final Dimension size = label.getPreferredSize();
  label.setPreferredSize(new Dimension(labelWidth, size.height + 2));

  if (tooltip != null && !"".equals(tooltip)) {
    label.setToolTipText("<html>" + tooltip + "</html>");
  }

  // Since we are in a scroll pane with glue at the bottom we do not want the
  // components to stretch vertically.
  main.setMaximumSize(new Dimension(Integer.MAX_VALUE, main
      .getPreferredSize().height));
  label.setMaximumSize(label.getPreferredSize());

  add(label);
  add(main);
}
 
Example 12
@Override
protected JPanel createToolInfoPanel() {
    JPanel container = new JPanel(new SpringLayout());

    JPanel configPanel = new JPanel(new SpringLayout());
    configPanel.setBorder(BorderFactory.createTitledBorder(Bundle.CTL_Panel_ConfigParams_Text()));

    JPanel panelToolFiles = new JPanel(new SpringLayout());

    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor(ToolAdapterConstants.MAIN_TOOL_FILE_LOCATION);
    propertyDescriptor.setValidator(new NotEmptyValidator());
    PropertyEditor editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent editorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    editorComponent.setMaximumSize(new Dimension(editorComponent.getMaximumSize().width, controlHeight));
    editorComponent.setPreferredSize(new Dimension(editorComponent.getPreferredSize().width, controlHeight));

    panelToolFiles.add(new JLabel(Bundle.CTL_Label_ToolLocation_Text()));
    panelToolFiles.add(editorComponent);

    propertyDescriptor = propertyContainer.getDescriptor(ToolAdapterConstants.WORKING_DIR);
    propertyDescriptor.setAttribute("directory", true);
    propertyDescriptor.setValidator((property, value) -> {
        if (value == null || value.toString().trim().isEmpty()) {
            throw new ValidationException(MessageFormat.format("Value for ''{0}'' must not be empty.",
                    property.getDescriptor().getDisplayName()));
        }
    });
    editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    editorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    editorComponent.setMaximumSize(new Dimension(editorComponent.getMaximumSize().width, controlHeight));
    editorComponent.setPreferredSize(new Dimension(editorComponent.getPreferredSize().width, controlHeight));

    panelToolFiles.add(new JLabel(Bundle.CTL_Label_WorkDir_Text()));
    panelToolFiles.add(editorComponent);

    SpringUtilities.makeCompactGrid(panelToolFiles, 2, 2, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    configPanel.add(panelToolFiles);

    JPanel checkPanel = new JPanel(new SpringLayout());

    propertyDescriptor = propertyContainer.getDescriptor(ToolAdapterConstants.HANDLE_OUTPUT);
    editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    editorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    editorComponent.setMaximumSize(new Dimension(editorComponent.getMaximumSize().width, controlHeight));
    editorComponent.setPreferredSize(new Dimension(editorComponent.getPreferredSize().width, controlHeight));

    checkPanel.add(editorComponent);
    checkPanel.add(new JLabel("Tool produces the name of the output product"));

    SpringUtilities.makeCompactGrid(checkPanel, 1, 2, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    configPanel.add(checkPanel);

    JLabel label = new JLabel(Bundle.CTL_Label_CmdLineTemplate_Text());
    configPanel.add(label);

    JScrollPane scrollPane = new JScrollPane(createTemplateEditorField());
    configPanel.add(scrollPane);

    SpringUtilities.makeCompactGrid(configPanel, 4, 1, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    container.add(configPanel);
    container.add(createPatternsPanel());
    SpringUtilities.makeCompactGrid(container, 2, 1, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    return container;
}
 
Example 13
static JComponent fixedHeight(JComponent component) {
    Dimension dim = component.getMaximumSize();
    dim.height = component.getPreferredSize().height;
    component.setMaximumSize(dim);
    return component;
}
 
Example 14
static JComponent fixedSize(JComponent component) {
    component.setMaximumSize(component.getPreferredSize());
    return component;
}
 
Example 15
void addComboField(JPanel parent, String labelText, String propertyName, List<String> values) {
    JLabel jLabel = new JLabel(labelText);
    parent.add(jLabel);

    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor(propertyName);
    propertyDescriptor.setNotEmpty(true);

    values.sort(Comparator.naturalOrder());

    propertyDescriptor.setValueSet(new ValueSet(values.toArray()));
    PropertyEditor editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent editorComp = editor.createEditorComponent(propertyDescriptor, bindingContext);
    if (editorComp instanceof JComboBox) {
        JComboBox comboBox = (JComboBox)editorComp;
        comboBox.setEditable(true);
    }
    editorComp.setMaximumSize(new Dimension(editorComp.getMaximumSize().width, controlHeight));

    customMenuLocation = new JTextField();
    customMenuLocation.setInputVerifier(new RequiredFieldValidator(Bundle.MSG_Empty_MenuLocation_Text()));
    customMenuLocation.setEnabled(false);

    JPanel subPanel = new JPanel(new SpringLayout());
    subPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
    JRadioButton rbExistingMenu = new JRadioButton(Bundle.CTL_Label_RadioButton_ExistingMenus(), true);
    rbMenuNew = new JRadioButton(Bundle.CTL_Label_RadioButton_NewMenu());
    ButtonGroup rbGroup = new ButtonGroup();
    rbGroup.add(rbExistingMenu);
    rbGroup.add(rbMenuNew);
    // this radio button should be able to capture focus even when the validator of the rbMenuNew says otherwise
    rbExistingMenu.setVerifyInputWhenFocusTarget(false);
    rbExistingMenu.addItemListener(e -> {
        editorComp.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
        customMenuLocation.setEnabled(e.getStateChange() == ItemEvent.DESELECTED);
    });
    subPanel.add(rbExistingMenu);
    subPanel.add(rbMenuNew);
    jLabel.setLabelFor(editorComp);
    subPanel.add(editorComp);
    subPanel.add(customMenuLocation);

    Dimension dimension = new Dimension(parent.getWidth() / 2, controlHeight);
    editorComp.setPreferredSize(dimension);
    customMenuLocation.setPreferredSize(dimension);

    subPanel.setPreferredSize(new Dimension(subPanel.getWidth(), (int)(2.5 * controlHeight)));
    subPanel.setMaximumSize(new Dimension(subPanel.getWidth(), (int) (2.5 * controlHeight)));

    makeCompactGrid(subPanel, 2, 2, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    parent.add(subPanel);
}
 
Example 16
Source Project: usergrid   File: LauncherFrame.java    License: Apache License 2.0 4 votes vote down vote up
public void setMaxWidth( JComponent jc, int width ) {
    Dimension max = jc.getMaximumSize();
    max.width = width;
    jc.setMaximumSize( max );
}
 
Example 17
Source Project: FancyBing   File: GuiUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void setUnlimitedSize(JComponent component)
{
    Dimension size = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
    component.setMaximumSize(size);
}
 
Example 18
static JComponent fixedSize(JComponent component) {
    component.setMaximumSize(component.getPreferredSize());
    return component;
}
 
Example 19
@Override
protected JPanel createPreProcessingPanel() {
    PropertyDescriptor propertyDescriptor = propertyContainer.getDescriptor("preprocessorExternalTool");
    PropertyEditor editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent firstEditorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    firstEditorComponent.setMaximumSize(new Dimension(firstEditorComponent.getMaximumSize().width,
                                                      controlHeight));
    firstEditorComponent.setPreferredSize(new Dimension(firstEditorComponent.getPreferredSize().width,
                                                        controlHeight));

    propertyDescriptor = propertyContainer.getDescriptor("processingWriter");
    editor = PropertyEditorRegistry.getInstance().findPropertyEditor(propertyDescriptor);
    JComponent secondEditorComponent = editor.createEditorComponent(propertyDescriptor, bindingContext);
    secondEditorComponent.setMaximumSize(new Dimension(secondEditorComponent.getMaximumSize().width,
                                                       controlHeight));
    secondEditorComponent.setPreferredSize(new Dimension(secondEditorComponent.getPreferredSize().width,
                                                         controlHeight));

    JCheckBox checkBoxComponent =
            (JCheckBox)createCheckboxComponent("preprocessTool", firstEditorComponent,
                                               newOperatorDescriptor.getPreprocessTool());
    checkBoxComponent.setText(Bundle.CTL_Label_PreprocessingTool_Text());

    JCheckBox writeComponent =
            (JCheckBox)createCheckboxComponent("writeForProcessing", secondEditorComponent,
                                               newOperatorDescriptor.shouldWriteBeforeProcessing());
    writeComponent.setText(Bundle.CTL_Label_WriteBefore_Text());

    JPanel preProcessingPanel = new JPanel(new SpringLayout());
    preProcessingPanel.add(checkBoxComponent);
    preProcessingPanel.add(firstEditorComponent);


    preProcessingPanel.add(writeComponent);
    preProcessingPanel.add(secondEditorComponent);

    SpringUtilities.makeCompactGrid(preProcessingPanel, 2, 2,
                                    DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);

    forwardFocusWhenTabKeyReleased(checkBoxComponent, firstEditorComponent);
    forwardFocusWhenTabKeyReleased(firstEditorComponent, writeComponent);
    forwardFocusWhenTabKeyReleased(writeComponent, secondEditorComponent);
    forwardFocusWhenTabKeyReleased(secondEditorComponent, this.tabbedPane);

    return preProcessingPanel;
}
 
Example 20
Source Project: CQL   File: JUtils.java    License: GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Sets the maximum width of a JComponent to its preferred width, thereby
 * preventing it from being expanded. The component itself is returned, to allow
 * shortcuts such as: xyz.add(JUtils.fixWidth(component)).
 *
 * @param c the component to be width-fixed
 * @return the component
 */
public static JComponent fixWidth(JComponent c) {
	Dimension max = c.getMaximumSize();

	max.width = c.getPreferredSize().width;

	c.setMaximumSize(max);

	return c;
}