Java Code Examples for java.awt.Dimension#setSize()

The following examples show how to use java.awt.Dimension#setSize() . 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: Axis.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get maximum tick label dimension
 * @param g Graphics2D
 * @return Maximum tick label dimension
 */
public Dimension getMaxTickDim(Graphics2D g) {
    this.updateTickLabels();
    Dimension dim = new Dimension();
    if (this.tickLabels.isEmpty()) {
        return dim;
    }
    
    Dimension dim1;
    double width = dim.getWidth(), height = dim.getHeight();
    for (int i = 0; i < this.tickLabels.size(); i++) {
        ChartText ct = this.tickLabels.get(i);
        ct.setAngle(this.tickLabelAngle);
        dim1 = ct.getTrueDimension(g);
        if (width < dim1.getWidth()){
            width = dim1.getWidth();
        }
        if (height < dim1.getHeight()) {
            height = dim1.getHeight();
        }
    }
    
    dim.setSize(width, height);
    return dim;
}
 
Example 2
Source File: LuckMenuItemUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * 重写方法,设置菜单的最小高度为20, 否则会出现菜单项大小不一致的情况。
 * </p>
 *
 * <p>
 * Rewrite method, set the minimum height of the menu is 20, otherwise the
 * menu item size will be inconsistent situation.
 * </p>
 */
@Override
protected Dimension getPreferredMenuItemSize(JComponent c,
                                             Icon checkIcon,
                                             Icon arrowIcon,
                                             int defaultTextIconGap)
{

    Dimension dimension = super.getPreferredMenuItemSize(c, checkIcon,
            arrowIcon, defaultTextIconGap);

    if (dimension != null && dimension.height < 20)
    {
        dimension.setSize(dimension.width, 20);
    }

    return dimension;
}
 
Example 3
Source File: GraphicsTests.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    double theta = Math.toRadians(15);
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xsize = sin * h + cos * w;
    double ysize = sin * w + cos * h;
    double scale = Math.min(w / xsize, h / ysize);
    xsize *= scale;
    ysize *= scale;
    AffineTransform at = new AffineTransform();
    at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
    at.translate(sin * h * scale, 0.0);
    at.rotate(theta);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 4
Source File: TextLineNumber.java    From RepDev with GNU General Public License v3.0 6 votes vote down vote up
/**
 *  Calculate the width needed to display the maximum line number
 */
private void setPreferredWidth()
{
	Element root = component.getDocument().getDefaultRootElement();
	int lines = root.getElementCount();
	int digits = Math.max(String.valueOf(lines).length(), minimumDisplayDigits);

	//  Update sizes when number of digits in the line number changes

	if (lastDigits != digits)
	{
		lastDigits = digits;
		FontMetrics fontMetrics = getFontMetrics( getFont() );
		int width = fontMetrics.charWidth( '0' ) * digits;
		Insets insets = getInsets();
		int preferredWidth = insets.left + insets.right + width;

		Dimension d = getPreferredSize();
		d.setSize(preferredWidth, HEIGHT);
		setPreferredSize( d );
		setSize( d );
	}
}
 
Example 5
Source File: GraphicsTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    double theta = Math.toRadians(15);
    double cos = Math.cos(theta);
    double sin = Math.sin(theta);
    double xsize = sin * h + cos * w;
    double ysize = sin * w + cos * h;
    double scale = Math.min(w / xsize, h / ysize);
    xsize *= scale;
    ysize *= scale;
    AffineTransform at = new AffineTransform();
    at.translate((w - xsize) / 2.0, (h - ysize) / 2.0);
    at.translate(sin * h * scale, 0.0);
    at.rotate(theta);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 6
Source File: SQLPanel.java    From bigtable-sql with Apache License 2.0 6 votes vote down vote up
CopyLastButton(IApplication app)
{
	super();
	final SquirrelResources rsrc = app.getResources();
	final ImageIcon icon = rsrc.getIcon(SquirrelResources.IImageNames.COPY_SELECTED);
	setIcon(icon);
          // i18n[SQLPanel.copylastbutton.hint=Copy current SQL history to entry area]
	String hint = s_stringMgr.getString("SQLPanel.copylastbutton.hint");
          setToolTipText(hint);
	Dimension dm = getPreferredSize();
	dm.setSize(dm.height, dm.height);
	setPreferredSize(dm);
	addActionListener(new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
		{
			copySelectedItemToEntryArea();
		}
	});
}
 
Example 7
Source File: MainControlPanel.java    From VanetSim with GNU General Public License v3.0 6 votes vote down vote up
public void tooglePanel(){
	Dimension size = simulatePanel_.getPreferredSize();
	hideBar_ = !hideBar_;
	if(hideBar_){
		//simulatePanel_.getHideBar_().setText("<");
		size.setSize(0, size.height < 800? 800: size.height);
	}
	else{
		//simulatePanel_.getHideBar_().setText(">");
		size.setSize(size.width+155, size.height < 800? 800: size.height);
	}
	setMinimumSize(new Dimension(size.width+50,400));
	editPanel_.setMinimumSize(new Dimension(size.width, size.height));
	//editPanel_.setSize(new Dimension(size.width, size.height));
	this.revalidate();
	this.repaint();
}
 
Example 8
Source File: LuckRadioBtnMenuItemUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * 重写方法,设置菜单的最小高度为20, 否则会出现菜单项大小不一致的情况。
 * </p>
 *
 * <p>
 * Rewrite method, set the minimum height of the menu is 20, otherwise the
 * menu item size will be inconsistent situation.
 * </p>
 */
protected Dimension getPreferredMenuItemSize(JComponent c,
                                             Icon checkIcon,
                                             Icon arrowIcon,
                                             int defaultTextIconGap)
{
    Dimension dimension = super.getPreferredMenuItemSize(c, checkIcon,
            arrowIcon, defaultTextIconGap);

    if (dimension != null && dimension.height < 20)
    {
        dimension.setSize(dimension.width, 20);
    }

    return dimension;
}
 
Example 9
Source File: GraphicsTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 10
Source File: GraphicsTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 11
Source File: GraphicsTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 12
Source File: GraphicsTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.scale(2.0, 2.0);
    g2d.transform(at);
    dim.setSize(w/2, h/2);
    ctx.pixscale = 4;
}
 
Example 13
Source File: GraphicsTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
    at.shear(0.1, 0.0);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 14
Source File: GraphicsTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(1.5, 1.5);
    g2d.transform(at);
    dim.setSize(w-3, h-3);
}
 
Example 15
Source File: GraphicsTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void init(Graphics2D g2d, Context ctx, Dimension dim) {
    int w = dim.width;
    int h = dim.height;
    AffineTransform at = new AffineTransform();
    at.translate(0.0, (h - (w*h)/(w + h*0.1)) / 2);
    at.shear(0.1, 0.0);
    g2d.transform(at);
    dim.setSize(scaleForTransform(at, dim));
}
 
Example 16
Source File: GIFImageWriter.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 17
Source File: GIFImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 18
Source File: SwingHelper.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
public static void setPreferredHeight(final JComponent component, final int height) {
    final Dimension size = component.getPreferredSize();
    size.setSize(size.getWidth(), JBUI.scale(height));
    component.setPreferredSize(size);
}
 
Example 19
Source File: GIFImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute the source region and destination dimensions taking any
 * parameter settings into account.
 */
private static void computeRegions(Rectangle sourceBounds,
                                   Dimension destSize,
                                   ImageWriteParam p) {
    ImageWriteParam param;
    int periodX = 1;
    int periodY = 1;
    if (p != null) {
        int[] sourceBands = p.getSourceBands();
        if (sourceBands != null &&
            (sourceBands.length != 1 ||
             sourceBands[0] != 0)) {
            throw new IllegalArgumentException("Cannot sub-band image!");
        }

        // Get source region and subsampling factors
        Rectangle sourceRegion = p.getSourceRegion();
        if (sourceRegion != null) {
            // Clip to actual image bounds
            sourceRegion = sourceRegion.intersection(sourceBounds);
            sourceBounds.setBounds(sourceRegion);
        }

        // Adjust for subsampling offsets
        int gridX = p.getSubsamplingXOffset();
        int gridY = p.getSubsamplingYOffset();
        sourceBounds.x += gridX;
        sourceBounds.y += gridY;
        sourceBounds.width -= gridX;
        sourceBounds.height -= gridY;

        // Get subsampling factors
        periodX = p.getSourceXSubsampling();
        periodY = p.getSourceYSubsampling();
    }

    // Compute output dimensions
    destSize.setSize((sourceBounds.width + periodX - 1)/periodX,
                     (sourceBounds.height + periodY - 1)/periodY);
    if (destSize.width <= 0 || destSize.height <= 0) {
        throw new IllegalArgumentException("Empty source region!");
    }
}
 
Example 20
Source File: FancyDropDownButton.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Dimension getPreferredSize() {
	Dimension prefSize = super.getPreferredSize();
	prefSize.setSize(prefSize.getWidth() + 75, prefSize.getHeight() + 20);
	return prefSize;
}