Java Code Examples for javax.swing.JComponent.setBounds()

The following are Jave code examples for showing how to use setBounds() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: RendererPropertyDisplayer.java   View Source Code Vote up 6 votes
public void paintComponent(Graphics g) {
    //Hack for issue 38132 - Beans are set via TTVBridge as a package
    //private property on the parent PropertyPanel (if there is one).
    //FindBeans() will locate the beans either in the model or as a 
    //property of the PropertyPanel (if an esoteric undocumented client property
    //is set on the PropertyPanel).  RendererFactory will set the env
    //value (if there is an env) to the value of ReusablePropertyEnv.NODE
    //(a performance hack to avoid creating 1 property env for each property
    //painted each time we paint).  Cool, huh?
    reusableEnv.setNode(EditorPropertyDisplayer.findBeans(this));

    JComponent comp = getRenderer(this);
    prepareRenderer(comp);
    comp.setBounds(0, 0, getWidth(), getHeight());

    if (comp instanceof InplaceEditor) {
        Component inner = findInnermostRenderer(comp);
        SwingUtilities.paintComponent(g, comp, this, 0, 0, getWidth(), getHeight());
        removeAll();
        return;
    }

    comp.paint(g);
}
 
Example 2
Project: incubator-netbeans   File: RendererPropertyDisplayer.java   View Source Code Vote up 6 votes
protected void prepareRenderer(JComponent comp) {
    comp.setBackground(getBackground());
    comp.setForeground(getForeground());
    comp.setBounds(0, 0, getWidth(), getHeight());

    JComponent innermost;

    if ((innermost = findInnermostRenderer(comp)) instanceof JComboBox) {
        if (comp.getLayout() != null) {
            comp.getLayout().layoutContainer(comp);
        }
    }

    if (!isTableUI() && ((InplaceEditor) comp).supportsTextEntry()) {
        innermost.setBackground(PropUtils.getTextFieldBackground());
        innermost.setForeground(PropUtils.getTextFieldForeground());
    }
}
 
Example 3
Project: incubator-netbeans   File: DefaultTabbedContainerUI.java   View Source Code Vote up 6 votes
private BufferedImage createImageOfComponent() {
    if (USE_SWINGPAINTING) {
        return null;
    }
    if (d.width == 0 || d.height == 0) {
        //Avoid problems in native graphics engine scaling if we should
        //end up with crazy values
        finish();
    }

    BufferedImage img =
        GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            createCompatibleImage(d.width, d.height);
    
    Graphics2D g2d = img.createGraphics();
    JComponent c = tabDisplayer;
    
    c.setBounds (0, 0, d.width, d.height);
    comp.paint (g2d);

    return img;
}
 
Example 4
Project: incubator-netbeans   File: HeaderComponent.java   View Source Code Vote up 5 votes
protected void paintComponent(Graphics g) {
    JTableHeader header = getHeader();
    setupHeader(header);
    TableCellRenderer renderer = header.getDefaultRenderer();
    JComponent component = (JComponent)renderer.getTableCellRendererComponent(
                           getTable(), "", isSelected && isPressed, isFocusOwner(), -1, 0); // NOI18N
    
    int height = header.getPreferredSize().height;
    component.setBounds(0, 0, getWidth(), height);
    component.setOpaque(false);
    getPainter().paintComponent(g, component, null, 0, 0, getWidth(), height, false);
}
 
Example 5
Project: OpenJSharp   File: MetalworksDocumentFrame.java   View Source Code Vote up 5 votes
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();

    int labelWidth = 0;
    for (Component comp : labels) {
        labelWidth = Math.max(labelWidth, comp.getPreferredSize().width);
    }

    int yPos = insets.top;

    Iterator<Component> fieldIter = fields.listIterator();
    Iterator<Component> labelIter = labels.listIterator();
    while (labelIter.hasNext() && fieldIter.hasNext()) {
        JComponent label = (JComponent) labelIter.next();
        JComponent field = (JComponent) fieldIter.next();
        int height = Math.max(label.getPreferredSize().height, field.
                getPreferredSize().height);
        label.setBounds(insets.left, yPos, labelWidth, height);
        field.setBounds(insets.left + labelWidth + xGap,
                yPos,
                c.getSize().width - (labelWidth + xGap + insets.left
                + insets.right),
                height);
        yPos += (height + yGap);
    }

}
 
Example 6
Project: jdk8u-jdk   File: MetalworksDocumentFrame.java   View Source Code Vote up 5 votes
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();

    int labelWidth = 0;
    for (Component comp : labels) {
        labelWidth = Math.max(labelWidth, comp.getPreferredSize().width);
    }

    int yPos = insets.top;

    Iterator<Component> fieldIter = fields.listIterator();
    Iterator<Component> labelIter = labels.listIterator();
    while (labelIter.hasNext() && fieldIter.hasNext()) {
        JComponent label = (JComponent) labelIter.next();
        JComponent field = (JComponent) fieldIter.next();
        int height = Math.max(label.getPreferredSize().height, field.
                getPreferredSize().height);
        label.setBounds(insets.left, yPos, labelWidth, height);
        field.setBounds(insets.left + labelWidth + xGap,
                yPos,
                c.getSize().width - (labelWidth + xGap + insets.left
                + insets.right),
                height);
        yPos += (height + yGap);
    }

}
 
Example 7
Project: openjdk-jdk10   File: MetalworksDocumentFrame.java   View Source Code Vote up 5 votes
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();

    int labelWidth = 0;
    for (Component comp : labels) {
        labelWidth = Math.max(labelWidth, comp.getPreferredSize().width);
    }

    int yPos = insets.top;

    Iterator<Component> fieldIter = fields.listIterator();
    Iterator<Component> labelIter = labels.listIterator();
    while (labelIter.hasNext() && fieldIter.hasNext()) {
        JComponent label = (JComponent) labelIter.next();
        JComponent field = (JComponent) fieldIter.next();
        int height = Math.max(label.getPreferredSize().height, field.
                getPreferredSize().height);
        label.setBounds(insets.left, yPos, labelWidth, height);
        field.setBounds(insets.left + labelWidth + xGap,
                yPos,
                c.getSize().width - (labelWidth + xGap + insets.left
                + insets.right),
                height);
        yPos += (height + yGap);
    }

}
 
Example 8
Project: incubator-netbeans   File: DefaultTabbedContainerUI.java   View Source Code Vote up 4 votes
public void layoutContainer(Container parent) {
    JComponent c = tabDisplayer;
    
    Object orientation = c.getClientProperty (
        TabDisplayer.PROP_ORIENTATION);
    
    Dimension d = tabDisplayer.getPreferredSize();
    Insets ins = container.getInsets();
    int width = parent.getWidth() - (ins.left + ins.right);
    int height = parent.getHeight() - (ins.top + ins.bottom);
    
    if (orientation == TabDisplayer.ORIENTATION_NORTH) {
        c.setBounds (ins.left, ins.top, 
            width, d.height);
        
        contentDisplayer.setBounds (ins.left, ins.top + d.height, 
            width, 
            parent.getHeight() - (d.height + ins.top + ins.bottom));
        
    } else if (orientation == TabDisplayer.ORIENTATION_SOUTH) {
        contentDisplayer.setBounds (ins.top, ins.left, width, 
            parent.getHeight() - (d.height + ins.top + ins.bottom));
        
        c.setBounds (ins.left, parent.getHeight() - (d.height + ins.top + ins.bottom),
            width, d.height);
    } else if (orientation == TabDisplayer.ORIENTATION_EAST) {
        contentDisplayer.setBounds (ins.left, ins.top, width - d.width,
            height);
        
        c.setBounds (parent.getWidth() - (ins.right + d.width), ins.top, 
            d.width, height);
        
    } else if (orientation == TabDisplayer.ORIENTATION_WEST) {
        c.setBounds (ins.left, ins.top, d.width, height);
        
        contentDisplayer.setBounds (ins.left + d.width, ins.top, 
            width - d.width, height);
        
    } else {
        throw new IllegalArgumentException ("Unknown orientation: " + orientation);
    }
}
 
Example 9
Project: Logisim   File: JTreeUtil.java   View Source Code Vote up 4 votes
@Override
public final void dragGestureRecognized(DragGestureEvent dge) {
	TreePath path = tree.getSelectionPath();
	if (path != null) {
		draggedNode = path.getLastPathComponent();
		if (drawImage) {
			Rectangle pathBounds = tree.getPathBounds(path); // getpathbounds
																// of
																// selectionpath
			JComponent lbl = (JComponent) tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode,
					false, tree.isExpanded(path), tree.getModel().isLeaf(path.getLastPathComponent()), 0,
					false);// returning the label
			lbl.setBounds(pathBounds);// setting bounds to lbl
			image = new BufferedImage(lbl.getWidth(), lbl.getHeight(),
					java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);// buffered
																	// image
																	// reference
																	// passing
																	// the
																	// label's
																	// ht
																	// and
																	// width
			Graphics2D graphics = image.createGraphics();// creating
															// the
															// graphics
															// for
															// buffered
															// image
			graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); // Sets
																								// the
																								// Composite
																								// for
																								// the
																								// Graphics2D
																								// context
			lbl.setOpaque(false);
			lbl.paint(graphics); // painting the graphics to label
			graphics.dispose();
		}
		dragSource.startDrag(dge, DragSource.DefaultMoveNoDrop, image, new Point(0, 0),
				new TransferableNode(draggedNode), this);
	}
}
 
Example 10
Project: scorekeeperfrontend   File: BracketPane.java   View Source Code Vote up 4 votes
private void setButtonByCenterLeft(JComponent button, int x, int y)
{
	Dimension butsize = button.getPreferredSize();
	butsize.height = 20;
	button.setBounds(x+11, y-butsize.height+2, butsize.width, butsize.height);
}