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

The following examples show how to use java.awt.Component#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: ProfilerTable.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
Component getRenderer(TableCellRenderer renderer, int row, int column, boolean sized) {
        isCustomRendering = true;
        try {
            Component comp = prepareRenderer(renderer, row, column);
//            comp.setSize(comp.getPreferredSize().width, getRowHeight());
            if (sized) {
                comp.setSize(comp.getPreferredSize().width, getRowHeight());
                if (!isLeadingAlign(comp)) {
                    TableColumnModel m = getColumnModel();
                    int x = -comp.getWidth();
                    int c = m.getColumn(column).getWidth();
                    int _column = convertColumnIndexToModel(column);
                    if (isScrollableColumn(_column)) {
                        x += Math.max(c, getColumnPreferredWidth(_column));
                    } else {
                        x += c;
                    }
                    comp.move(x - m.getColumnMargin(), 0);
                }
            }
            
            return comp;
        } finally {
            isCustomRendering = false;
        }
    }
 
Example 2
Source File: ProfilerTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
Component getRenderer(TableCellRenderer renderer, int row, int column, boolean sized) {
        isCustomRendering = true;
        try {
            Component comp = prepareRenderer(renderer, row, column);
//            comp.setSize(comp.getPreferredSize().width, getRowHeight());
            if (sized) {
                comp.setSize(comp.getPreferredSize().width, getRowHeight());
                if (!isLeadingAlign(comp)) {
                    TableColumnModel m = getColumnModel();
                    int x = -comp.getWidth();
                    int c = m.getColumn(column).getWidth();
                    int _column = convertColumnIndexToModel(column);
                    if (isScrollableColumn(_column)) {
                        x += Math.max(c, getColumnPreferredWidth(_column));
                    } else {
                        x += c;
                    }
                    comp.move(x - m.getColumnMargin(), 0);
                }
            }
            
            return comp;
        } finally {
            isCustomRendering = false;
        }
    }
 
Example 3
Source File: ToggleButtonMenuItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Icon createMenuIcon(Icon icon, Component decorator) {
    int h = menuIconSize();
    int w = UIUtils.isAquaLookAndFeel() ? h + 4 : h;

    BufferedImage i = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics g = i.getGraphics();

    if (decorator != null) {
        decorator.setSize(w, h);
        decorator.paint(g);
    }

    icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconHeight()) / 2);
    g.dispose();

    return new ImageIcon(i);
}
 
Example 4
Source File: LineLayout.java    From oim-fx with MIT License 6 votes vote down vote up
private void layoutContainerV(Container target) {
    int maxWidth = 0;
    Dimension size;
    int width;
    Insets insets = target.getInsets();

    for (Component component : target.getComponents()) {
        if (component.isVisible()) {
            size = component.getPreferredSize();

            if (fillComponents.contains(component)) {
                width = target.getWidth() - insets.left - insets.right - leftGap - rightGap;
            } else {
                width = size.width;

                if (width > maxWidth) {
                    maxWidth = width;
                }
            }

            component.setSize(width, size.height);
        }
    }

    moveComponentsV(target, maxWidth);
}
 
Example 5
Source File: SlideContainer.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Override
public Component add(Component comp) {
    setsize(comp.getPreferredSize());
    Component[] comps = getComponents();
    if (comps.length > 0) {
        oldComponent = comps[0];
    }
    if (comp.equals(oldComponent)) {
        return super.add(comp);
    }
    if (oldComponent != null) {
        putLayer((JComponent) oldComponent, JLayeredPane.DEFAULT_LAYER);
    }
    Component returnResult = super.add(comp);
    putLayer((JComponent) comp, JLayeredPane.DRAG_LAYER);
    comp.setSize(getPreferredSize());
    comp.setVisible(true);
    comp.setLocation(0, 0 - getPreferredSize().height);
    slideFromTop(comp, oldComponent);
    return returnResult;
}
 
Example 6
Source File: ViewTooltips.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Set the cell renderer we will proxy.
 */
public void setComponent (Component jc, JComponent owner) {
    Dimension dd = jc.getPreferredSize();
    Rectangle currentScreenBounds = Utilities.getUsableScreenBounds();
    // get some reasonable limit for the width
    int width = Math.min(dd.width, 2 * currentScreenBounds.width);
    int height = Math.min(dd.height + 2, 2 * currentScreenBounds.height);
    Image nue = !Utilities.isMac() ? owner.createVolatileImage(width, height) :
                new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = nue.getGraphics();
    g.setColor (bg);
    g.fillRect (0, 0, width, dd.height + 2);
    if( jc instanceof Container && !jc.isValid() ) {
        //#214739
        jc.setSize( width, dd.height );
        jc.doLayout();
    }
    SwingUtilities.paintComponent(g, jc, this, 0, 0, width, dd.height + 2);
    g.dispose();
    setImage (nue);
}
 
Example 7
Source File: Test6943780.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    pane.addTab("first", new JButton("first"));
    pane.addTab("second", new JButton("second"));
    for (Component component : pane.getComponents()) {
        component.setSize(100, 100);
    }
}
 
Example 8
Source File: MetalworksPrefs.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
Example 9
Source File: GridView.java    From swift-k with Apache License 2.0 5 votes vote down vote up
private int layout(GridView.Tree t, int x, int y, int w, int h, int index) {
    if (t == null) {
        return index;
    }
    if (t.splitType == Tree.NONE) {
        if (cellCount > index) {
            Component c = getComponent(index);
            c.setSize(w, h);
            c.setLocation(x, y);
        }
        return index + 1;
    }
    else if (t.splitType == Tree.V) {
        int h1 = (int) (t.splitPosition * h);
        int h2 = h - h1;
        setDivider(Tree.V, x, y + h1 - DIVIDER_SIZE / 2, w, DIVIDER_SIZE, h, t);
        index = layout(t.first, x, y, w, h1 - DIVIDER_SIZE / 2, index);
        return layout(t.second, x, y + h1 + DIVIDER_SIZE / 2, w, h2, index);
    }
    else if (t.splitType == Tree.H) {
        int w1 = (int) (t.splitPosition * w);
        int w2 = w - w1;
        setDivider(Tree.H, x + w1 - DIVIDER_SIZE / 2, y, DIVIDER_SIZE, h, w, t);
        index = layout(t.first, x, y, w1 - DIVIDER_SIZE / 2, h, index);
        return layout(t.second, x + w1 + DIVIDER_SIZE / 2, y, w2, h, index);
    }
    return index;
}
 
Example 10
Source File: MetalworksPrefs.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
Example 11
Source File: Test6943780.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    pane.addTab("first", new JButton("first"));
    pane.addTab("second", new JButton("second"));
    for (Component component : pane.getComponents()) {
        component.setSize(100, 100);
    }
}
 
Example 12
Source File: MetalworksPrefs.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
Example 13
Source File: Test6943780.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    pane.addTab("first", new JButton("first"));
    pane.addTab("second", new JButton("second"));
    for (Component component : pane.getComponents()) {
        component.setSize(100, 100);
    }
}
 
Example 14
Source File: Test6943780.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    pane.addTab("first", new JButton("first"));
    pane.addTab("second", new JButton("second"));
    for (Component component : pane.getComponents()) {
        component.setSize(100, 100);
    }
}
 
Example 15
Source File: Test6943780.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    pane.addTab("first", new JButton("first"));
    pane.addTab("second", new JButton("second"));
    for (Component component : pane.getComponents()) {
        component.setSize(100, 100);
    }
}
 
Example 16
Source File: Test6943780.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    pane.addTab("first", new JButton("first"));
    pane.addTab("second", new JButton("second"));
    for (Component component : pane.getComponents()) {
        component.setSize(100, 100);
    }
}
 
Example 17
Source File: ProfilerTableHovers.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private Component getRenderer(int row, int column) {
    TableCellRenderer renderer = table.getCellRenderer(row, column);
    Component _renderer = table.getRenderer(renderer, row, column, true);
    _renderer.setSize(Math.min(_renderer.getWidth(), MAX_RENDERER_WIDTH), _renderer.getHeight());
    return _renderer;
}
 
Example 18
Source File: SmartFlowLayout.java    From workcraft with MIT License 4 votes vote down vote up
private Dimension doLayout(Container target) {
    synchronized (target.getTreeLock()) {
        boolean useBaseline = getAlignOnBaseline();
        if (useBaseline) {
            throw new NotSupportedException("BaseLine is not supported.");
        }

        Insets insets = target.getInsets();
        int maxwidth = target.getWidth() - (insets.left + insets.right + hgap * 2);
        int nmembers = target.getComponentCount();
        int x = 0;
        int y = insets.top + vgap;
        int rowh = 0;
        int start = 0;
        boolean ltr = target.getComponentOrientation().isLeftToRight();
        for (int i = 0; i < nmembers; i++) {
            Component m = target.getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();

                if (applyLayout) {
                    m.setSize(d.width, d.height);
                }

                if (x > 0) {
                    x += hgap;
                }
                x += d.width;
                rowh = Math.max(rowh, d.height);

                if (x >= maxwidth) {
                    if (fit(target, insets.left + hgap, y, maxwidth, rowh, start, i + 1, ltr)) {
                        start = i + 1;
                        x = 0;
                        y += vgap + rowh;
                        rowh = 0;
                    } else {
                        int end = i;
                        if (start == end) {
                            end++;
                        }
                        stretch(target, insets.left + hgap, y, maxwidth, rowh, start, end, ltr);
                        start = end;
                        x = d.width;
                        y += vgap + rowh;
                        rowh = d.height;
                    }
                }
            }
        }
        //moveComponents(target, insets.left + hgap, y, 0, rowh, start, nmembers, ltr);
        stretch(target, insets.left + hgap, y, maxwidth, rowh, start, nmembers, ltr);

        return new Dimension(maxwidth, y + rowh + (rowh != 0 ? vgap : 0));
    }
}
 
Example 19
Source File: ProfilerTableHovers.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Component getRenderer(int row, int column) {
    TableCellRenderer renderer = table.getCellRenderer(row, column);
    Component _renderer = table.getRenderer(renderer, row, column, true);
    _renderer.setSize(Math.min(_renderer.getWidth(), MAX_RENDERER_WIDTH), _renderer.getHeight());
    return _renderer;
}
 
Example 20
Source File: VerticalFlowLayout.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *  Description of the Method
 *
 *@param  target  Description of Parameter
 */
public void layoutContainer(Container target) {
	synchronized (target.getTreeLock()) {
		Insets insets = target.getInsets();
		int maxheight = target.getHeight() - (insets.top + insets.bottom) - 2 * _vgap;
	    int maxwidth = target.getWidth() - (insets.left + insets.right) - 2 * _hgap;
		int nmembers = target.getComponentCount();

		Dimension preferredSize = preferredLayoutSize(target);
		Dimension targetSize = target.getSize();

		int y = (_valign == TOP)    ? insets.top
			  : (_valign == CENTER) ? (targetSize.height - preferredSize.height) / 2
			  :						  targetSize.height - preferredSize.height - insets.bottom;

		for (int i = 0; i < nmembers; i++) {
			Component m = target.getComponent(i);
			if (m.isVisible()) {
				Dimension d = m.getPreferredSize();
		        if (_hfill ) {
		        	m.setSize(maxwidth, d.height);
		            d.width = maxwidth;
		        }
		        else {
		        	m.setSize(d.width, d.height);
		        }

				if ((y + d.height) <= maxheight) {
					if (y > 0) {
						y += _vgap;
					}

					int x = (_halign == LEFT) ? insets.left
						: (_halign == CENTER) ? (targetSize.width - d.width) / 2
						:						targetSize.width - d.width - insets.right;

					m.setLocation(x + _hgap, y + _vgap);

					y += d.getHeight();

				}
				else {
					break;
				}
			}
		}
	}
}