Java Code Examples for java.awt.Component#setMinimumSize()

The following examples show how to use java.awt.Component#setMinimumSize() . 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
Source File: ListLayout.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void layoutContainer(Container parent) {
    Dimension dim = preferredLayoutSize(parent);
    Insets ins = parent.getInsets();
    int top = ins.top;
    boolean first = true;
    for (Component c : parent.getComponents()) {
        if (!c.isVisible()) {
            continue;
        }
        if (!first) {
            top += border;
        }
        Dimension pref = c.getPreferredSize();
        c.setPreferredSize(new Dimension(dim.width, pref.height));
        c.setMinimumSize(new Dimension(dim.width, pref.height));
        c.setBounds(0, top, dim.width, pref.height);
        top += pref.height;
        first = false;
    }

}
 
Example 2
Source File: SimpleBoxFormBuilder.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Add a component to Form at position pointer by cursor, 
 * Increments cursor by one.
 * @param c Component to add
 */
public void add(Component c) {
	if (debug) {
		if (c instanceof JComponent)
			((JComponent) c).setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
	}
	addBox(c);

	if (rowHeight < Short.MAX_VALUE) {
		Dimension d = c.getPreferredSize();
		d.height = rowHeight;
		c.setPreferredSize(d);

		c.setMinimumSize(d);
		
		if (!c.isMaximumSizeSet() || c.getMaximumSize().getHeight() > rowHeight) {
			c.setMaximumSize(new Dimension(Short.MAX_VALUE, rowHeight));
		}
	}
	
}
 
Example 3
Source File: DimensionEncapsulation.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 4
Source File: DimensionEncapsulation.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 5
Source File: ProfilerPopupMenu.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void add(Component comp, Object constraints) {
    if (forceBackground && !UIUtils.isOracleLookAndFeel() && comp instanceof JComponent)
        ((JComponent)comp).setOpaque(false);
    if (forceBackground && !UIUtils.isNimbusLookAndFeel()) comp.setForeground(getForeground());
    comp.setMinimumSize(comp.getPreferredSize());
    super.add(comp, constraints);
}
 
Example 6
Source File: DimensionEncapsulation.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 7
Source File: DimensionEncapsulation.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 8
Source File: DimensionEncapsulation.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 9
Source File: DimensionEncapsulation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 10
Source File: DimensionEncapsulation.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 11
Source File: DimensionEncapsulation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(final Component c) {
    try {
        test(c);
        c.setMinimumSize(new Dimension(100, 10));
        c.setMaximumSize(new Dimension(200, 20));
        c.setPreferredSize(new Dimension(300, 30));
        test(c);
    } catch (final Throwable ignored) {
        failures.add(c);
    }
}
 
Example 12
Source File: AddPlacePrompt.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void addInput(JPanel p, Component c, int inputSize, GridBagConstraints gbc) {
   gbc.gridx = 1;
   gbc.fill = inputSize > 0 ? GridBagConstraints.NONE : GridBagConstraints.HORIZONTAL;
   gbc.anchor = GridBagConstraints.NORTHWEST;
   gbc.weightx = inputSize > 0 ? 0 : 1;
   if (inputSize > 0) {
      c.setPreferredSize(new Dimension(inputSize, c.getPreferredSize().height));
      c.setMinimumSize(c.getPreferredSize());
   }
   p.add(c, gbc.clone());
}
 
Example 13
Source File: BillingInformationPrompt.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void addInput(JPanel p, Component c, int inputSize, GridBagConstraints gbc) {
   gbc.gridx = 1;
   gbc.fill = inputSize > 0 ? GridBagConstraints.NONE : GridBagConstraints.HORIZONTAL;
   gbc.anchor = GridBagConstraints.NORTHWEST;
   gbc.weightx = inputSize > 0 ? 0 : 1;
   if (inputSize > 0) {
      c.setPreferredSize(new Dimension(inputSize, c.getPreferredSize().height));
      c.setMinimumSize(c.getPreferredSize());
   }
   p.add(c, gbc.clone());
}
 
Example 14
Source File: DeletePrompt.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void addInput(JPanel p, Component c, int inputSize, GridBagConstraints gbc) {
   gbc.gridx = 1;
   gbc.fill = inputSize > 0 ? GridBagConstraints.NONE : GridBagConstraints.HORIZONTAL;
   gbc.anchor = GridBagConstraints.NORTHWEST;
   gbc.weightx = inputSize > 0 ? 0 : 1;
   if (inputSize > 0) {
      c.setPreferredSize(new Dimension(inputSize, c.getPreferredSize().height));
      c.setMinimumSize(c.getPreferredSize());
   }
   p.add(c, gbc.clone());
}
 
Example 15
Source File: ProfilerPopupMenu.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void add(Component comp, Object constraints) {
    if (forceBackground && !UIUtils.isOracleLookAndFeel() && comp instanceof JComponent)
        ((JComponent)comp).setOpaque(false);
    comp.setMinimumSize(comp.getPreferredSize());
    super.add(comp, constraints);
}
 
Example 16
Source File: BookmarksView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void fixScrollPaneinSplitPaneJDKIssue(Component c) {
    c.setMinimumSize(new Dimension(10, 10)); // Workaround for JSplitPane-containing-JScrollPane JDK bug
}
 
Example 17
Source File: UIHelper.java    From java-photoslibrary with Apache License 2.0 4 votes vote down vote up
public static void setFixedSize(Component component, Dimension dimension) {
  component.setSize(dimension);
  component.setPreferredSize(dimension);
  component.setMaximumSize(dimension);
  component.setMinimumSize(dimension);
}
 
Example 18
Source File: TablePanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Updates the component in the specified cell.
 *
 * @param rowIndex
 * @param columnIndex
 */
private void updateComponent(int rowIndex, int columnIndex) {
	Pair<Integer, Integer> key = new Pair<>(rowIndex, columnIndex);

	// remove old component
	Component oldComponent = mapOfComponents.get(key);
	if (oldComponent != null) {
		innerPanel.remove(oldComponent);
	}

	// add updated component to panel instead
	Component updatedComponent = createComponentForCell(rowIndex, columnIndex);

	// add dimension constraint (if applicable)
	if (isConstraintsUsed()) {
		updatedComponent.setMinimumSize(constraints[columnIndex]);
		updatedComponent.setMaximumSize(constraints[columnIndex]);
		updatedComponent.setPreferredSize(constraints[columnIndex]);
	}

	if (isConstraintsUsed()) {
		gbc.weightx = 0.0;
	} else {
		if (Collection.class.isAssignableFrom(model.getColumnClass(columnIndex))) {
			gbc.weightx = 0.1;
		} else {
			gbc.weightx = 1.0 / model.getColumnCount();
		}
	}
	gbc.weighty = 0.0;
	if (isConstraintsUsed() && fillerMode == FillerMode.NONE) {
		gbc.fill = GridBagConstraints.VERTICAL;
	} else {
		gbc.fill = GridBagConstraints.BOTH;
	}
	gbc.gridx = columnIndex;
	gbc.gridy = rowIndex;
	innerPanel.add(updatedComponent, gbc);
	innerPanel.revalidate();
	innerPanel.repaint();

	mapOfComponents.put(key, updatedComponent);
}
 
Example 19
Source File: InformationWindow.java    From wpcleaner with Apache License 2.0 4 votes vote down vote up
/**
 * @return Window components.
 */
@Override
protected Component createComponents() {
  JPanel panel = new JPanel(new GridBagLayout());

  // Initialize constraints
  GridBagConstraints constraints = new GridBagConstraints();
  constraints.fill = GridBagConstraints.HORIZONTAL;
  constraints.gridheight = 1;
  constraints.gridwidth = 1;
  constraints.gridx = 0;
  constraints.gridy = 0;
  constraints.insets = new Insets(2, 2, 2, 2);
  constraints.ipadx = 0;
  constraints.ipady = 0;
  constraints.weightx = 0;
  constraints.weighty = 0;

  // Title
  lblTitle = Utilities.createJLabel(title);
  lblTitle.setHorizontalAlignment(SwingConstants.LEADING);
  constraints.gridx = 0;
  constraints.weightx = 0;
  panel.add(lblTitle, constraints);
  constraints.gridy++;

  // Information
  Component component = null;
  if (html) {
    textInformation = HTMLPane.createHTMLPane(null);
    component = textInformation;
  } else {
    textPane = new JTextPane();
    textPane.setEditable(false);
    component = textPane;
  }
  JScrollPane scrollPane = new JScrollPane(component);
  scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  component = scrollPane;
  component.setPreferredSize(new Dimension(500, 500));
  component.setMinimumSize(new Dimension(100, 100));
  lblTitle.setLabelFor(component);
  constraints.fill = GridBagConstraints.BOTH;
  constraints.gridx = 0;
  constraints.weighty = 1;
  constraints.weightx = 1;
  panel.add(component, constraints);
  constraints.gridy++;

  // Buttons
  JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
  buttonClose = ActionDispose.createButton(getParentComponent(), true, false);
  buttonPanel.add(buttonClose);
  constraints.fill = GridBagConstraints.NONE;
  constraints.gridx = 0;
  constraints.weightx = 1;
  constraints.weighty = 0;
  panel.add(buttonPanel, constraints);
  constraints.gridy++;

  return panel;
}
 
Example 20
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Sets a {@link Component}'s min, max & preferred sizes to a specific size.
 *
 * @param comp The {@link Component} to work on.
 * @param size The size to set the component to.
 */
public static void setOnlySize(Component comp, Dimension size) {
    comp.setMinimumSize(size);
    comp.setMaximumSize(size);
    comp.setPreferredSize(size);
}