javax.swing.JComponent#setSize ( )源码实例Demo

下面列出了javax.swing.JComponent#setSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: HBaseClient   文件: AppFrame.java
/**
 * 初始化主窗口信息
 */
public void init()
{
    this.setJMenuBar((JMenuBar)XJava.getObject("xmMainMenuBar"));
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add((Component)XJava.getObject("xpMain") ,BorderLayout.CENTER);
    this.setEnabled(false);
    
    JComponent v_JC = ((JComponent)XJava.getObject("xlTables"));
    v_JC.setSize(50 ,v_JC.getHeight());
    
    this.showHintInfo("请稍后,正在访问数据库..." ,Color.BLUE);
    
    this.initListModel();
    this.initTableModel();
    this.initTablesInfo();
    
    this.setEnabled(true);
    this.showHintInfo("欢迎使用!");
}
 
源代码2 项目: netbeans   文件: HideableBarRenderer.java
public void paint(Graphics g) {
    g.setColor(getBackground());
    g.fillRect(location.x, location.y, size.width, size.height);
    
    JComponent component = mainRenderer.getComponent();
    int componentWidth = component.getPreferredSize().width;
    int componentX = size.width - componentWidth;
    
    mainRenderer.move(location.x + componentX, location.y);
    component.setSize(componentWidth, size.height);
    component.paint(g);
    
    if (numberPercentRenderer == null || numberPercentRenderer.valueRenderers()[1].getComponent().isVisible()) {
        int freeWidth = size.width - maxRendererWidth - renderersGap();
        if (freeWidth >= MIN_BAR_WIDTH) {
            barRenderer.setSize(Math.min(freeWidth, MAX_BAR_WIDTH), size.height);
            barRenderer.move(location.x, location.y);
            barRenderer.paint(g);
        }
    }
}
 
源代码3 项目: netbeans   文件: ComponentMorpher2.java
private Image getComponentImage(JComponent component) {
    // Initial component sizing & layout
    component.setSize((getClientSize().width == 0) ? component.getPreferredSize() : getClientSize()); // try to fit the component to ComponentMorpher
    component.doLayout(); // layout component

    // Correct component sizing & layout
    component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
    component.doLayout(); // layout component

    // One more iteration because of nested JTextAreas
    component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
    component.doLayout(); // layout component

    // Paint component into BufferedImage
    BufferedImage componentImage = new BufferedImage(component.getSize().width, component.getSize().height,
                                                     BufferedImage.TYPE_INT_RGB);
    component.printAll(componentImage.getGraphics());

    return componentImage;
}
 
源代码4 项目: visualvm   文件: HideableBarRenderer.java
public void paint(Graphics g) {
    g.setColor(getBackground());
    g.fillRect(location.x, location.y, size.width, size.height);
    
    JComponent component = mainRenderer.getComponent();
    int componentWidth = component.getPreferredSize().width;
    int componentX = size.width - componentWidth;
    
    mainRenderer.move(location.x + componentX, location.y);
    component.setSize(componentWidth, size.height);
    component.paint(g);
    
    if (barRenderer.isVisible()) {
        int freeWidth = size.width - maxRendererWidth - renderersGap();
        if (freeWidth >= MIN_BAR_WIDTH) {
            barRenderer.setSize(Math.min(freeWidth, MAX_BAR_WIDTH), size.height);
            barRenderer.move(location.x, location.y);
            barRenderer.paint(g);
        }
    }
}
 
源代码5 项目: visualvm   文件: ComponentMorpher2.java
private Image getComponentImage(JComponent component) {
    // Initial component sizing & layout
    component.setSize((getClientSize().width == 0) ? component.getPreferredSize() : getClientSize()); // try to fit the component to ComponentMorpher
    component.doLayout(); // layout component

    // Correct component sizing & layout
    component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
    component.doLayout(); // layout component

    // One more iteration because of nested JTextAreas
    component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
    component.doLayout(); // layout component

    // Paint component into BufferedImage
    BufferedImage componentImage = new BufferedImage(component.getSize().width, component.getSize().height,
                                                     BufferedImage.TYPE_INT_RGB);
    component.printAll(componentImage.getGraphics());

    return componentImage;
}
 
源代码6 项目: netbeans   文件: SystemAction.java
/** Create an icon.
* @param comp a component, which must be unattached to a container
*             and should not be used for other purposes
*/
public ComponentIcon(JComponent comp) {
    if (comp.getParent() != null) {
        throw new IllegalArgumentException();
    }

    this.comp = comp;

    Dimension size = comp.getPreferredSize();

    // Careful! If you have e.g. a JLabel with empty text, width = 0 => exceptions.
    // Must make sure it is at least a reasonable size.
    comp.setSize(Math.max(size.width, 16), Math.max(size.height, 16));
}
 
源代码7 项目: netbeans   文件: ComponentMorpher.java
private JComponent layoutComponent(JComponent component) {
    // Initial component sizing & layout
    if (getClientSize().width > 0) {
        component.setSize(getClientSize()); // try to fit the component to ComponentMorpher
        component.validate(); // layout component

        // Correct component sizing & layout
        component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
        component.validate(); // layout component
    }

    return component;
}
 
源代码8 项目: netbeans   文件: PalettePanel.java
@Override
public void layoutContainer( Container parent ) {
    int width = getWidth ();

    int height = 0;
    for( int i=0; i<descriptors.length; i++ ) {
        CategoryDescriptor paletteCategoryDescriptor = descriptors[i];
        paletteCategoryDescriptor.setPositionY( height );
        JComponent comp = paletteCategoryDescriptor.getComponent();
        comp.setSize( width, comp.getPreferredSize().height );
        height += paletteCategoryDescriptor.getComponent().getHeight();
    }
}
 
源代码9 项目: openjdk-jdk9   文件: bug8132119.java
private static JComponent createComponent(String str) {
    JComponent comp = new JLabel(str);
    comp.setSize(WIDTH, HEIGHT);
    comp.putClientProperty(TextAttribute.NUMERIC_SHAPING, NUMERIC_SHAPER);
    comp.setFont(getFont());
    return comp;
}
 
源代码10 项目: visualvm   文件: ComponentMorpher.java
private JComponent layoutComponent(JComponent component) {
    // Initial component sizing & layout
    if (getClientSize().width > 0) {
        component.setSize(getClientSize()); // try to fit the component to ComponentMorpher
        component.validate(); // layout component

        // Correct component sizing & layout
        component.setSize(new Dimension(getClientSize().width, component.getPreferredSize().height)); // Width of component is fixed, update height
        component.validate(); // layout component
    }

    return component;
}
 
源代码11 项目: pumpernickel   文件: PaddingInfo.java
/**
 * This makes some visual changes to the component and its children. Shortly
 * after calling this method, the <code>restore()</code> method needs to be
 * called.
 */
private static void prep(Component c) {
	if (c instanceof JComponent) {
		JComponent jc = (JComponent) c;
		if (jc.isOpaque()) {
			jc.setOpaque(false);
			jc.putClientProperty(USED_TO_BE_OPAQUE, Boolean.TRUE);
		}

		Dimension preferredSize = c.getPreferredSize();
		if (greaterThanOrEqualTo(jc.getSize(), preferredSize) == false) {
			jc.putClientProperty(SIZE, c.getSize());
			jc.setSize(preferredSize);
		}
	}
	if (c instanceof JSlider) {
		JSlider s = (JSlider) c;
		ChangeListener[] listeners = s.getChangeListeners();
		int mid = (s.getMinimum() + s.getMaximum()) / 2;
		if (mid != s.getValue()) {
			s.putClientProperty(CHANGE_LISTENERS, listeners);
			for (int a = 0; a < listeners.length; a++) {
				s.removeChangeListener(listeners[a]);
			}
			s.putClientProperty(SLIDER_VALUE, new Integer(s.getValue()));
			s.setValue(mid);
		}
	}
	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (int a = 0; a < c2.getComponentCount(); a++) {
			prep(c2.getComponent(a));
		}
	}
	if (c.isValid() == false)
		c.validate();
}
 
源代码12 项目: pumpernickel   文件: PaddingInfo.java
/**
 * Should be called shortly after <code>prep()</code>.
 */
private static void restore(Component c) {
	if (c instanceof JComponent) {
		JComponent jc = (JComponent) c;
		Boolean b = (Boolean) jc.getClientProperty(USED_TO_BE_OPAQUE);
		if (b != null && b.booleanValue()) {
			jc.setOpaque(true);
		}
		jc.putClientProperty(USED_TO_BE_OPAQUE, null);

		Dimension d = (Dimension) jc.getClientProperty(SIZE);
		if (d != null) {
			jc.setSize(d);
			jc.putClientProperty(SIZE, null);
		}
	}
	if (c instanceof JSlider) {
		JSlider s = (JSlider) c;
		ChangeListener[] listeners = (ChangeListener[]) s
				.getClientProperty(CHANGE_LISTENERS);
		Integer i = (Integer) s.getClientProperty(SLIDER_VALUE);
		if (i != null)
			s.setValue(i.intValue());
		if (listeners != null) {
			for (int a = 0; a < listeners.length; a++) {
				s.addChangeListener(listeners[a]);
			}
		}
		s.putClientProperty(SLIDER_VALUE, null);
		s.putClientProperty(CHANGE_LISTENERS, null);
	}
	if (c instanceof Container) {
		Container c2 = (Container) c;
		for (int a = 0; a < c2.getComponentCount(); a++) {
			restore(c2.getComponent(a));
		}
	}
}
 
源代码13 项目: pumpernickel   文件: MockComponent.java
/**
 * Creates a MockComponent that resembles the argument component.
 * <P>
 * Note this method will traverse c and its subcomponents and may
 * temporarily change properties of inner components: such as the focused
 * state, the visibility, etc.
 * <P>
 * The goal is of this component is not to mirror the exact state of a
 * component, but rather to provide a sample image of this component in its
 * plain, unmodified, unused state.
 * 
 * @param c
 */
public MockComponent(JComponent c) {
	Dimension preferredSize = c.getPreferredSize();
	Dimension currentSize = c.getSize();

	Dimension d = new Dimension(Math.max(preferredSize.width,
			currentSize.width), Math.max(preferredSize.height,
			currentSize.height));

	if (currentSize.width == 0 || currentSize.height == 0) {
		// if the component isn't visible yet
		c.setSize(d);
		c.doLayout();
	}

	storeState(c);

	image = new BufferedImage(d.width, d.height,
			BufferedImage.TYPE_INT_ARGB);

	Graphics2D g = image.createGraphics();
	g.setComposite(AlphaComposite.Clear);
	g.fillRect(0, 0, d.width, d.height);
	g.setComposite(AlphaComposite.SrcOver);

	c.paint(g);
	g.dispose();
	setPreferredSize(d);
	setMinimumSize(d);
	setMaximumSize(d);
	setOpaque(c.isOpaque());
	setName(c.getName());
	setToolTipText(c.getToolTipText());

	restoreState(c);
}
 
源代码14 项目: rapidminer-studio   文件: PlotterAdapter.java
@Override
public void render(Graphics graphics, int width, int height) {
	JComponent renderComponent = getRenderComponent();
	renderComponent.setSize(width, height);
	renderComponent.setDoubleBuffered(false);
	renderComponent.paint(graphics);
	renderComponent.setDoubleBuffered(true);
}
 
源代码15 项目: filthy-rich-clients   文件: TextHighlightingDemo.java
private void installInLayeredPane(JComponent component) {
    JLayeredPane layeredPane = getRootPane().getLayeredPane();
    layeredPane.add(component, JLayeredPane.PALETTE_LAYER, 20);
    Dimension size = component.getPreferredSize();
    component.setSize(size);
    component.setLocation((getWidth() - size.width) / 2,
            (getHeight() - size.height) / 2);
    component.revalidate();
    component.setVisible(true);
}
 
源代码16 项目: javamelody   文件: ShadowPopupFactory.java
/**
 * Reinitializes this ShadowPopup using the given parameters.
 *
 * @param newOwner component mouse coordinates are relative to, may be null
 * @param newContents the contents of the popup
 * @param newX the desired x location of the popup
 * @param newY the desired y location of the popup
 * @param newPopup the popup to wrap
 */
private void reset(Component newOwner, Component newContents, int newX, int newY,
		Popup newPopup) {
	this.owner = newOwner;
	this.contents = newContents;
	this.popup = newPopup;
	this.x = newX;
	this.y = newY;
	if (newOwner instanceof JComboBox) {
		return;
	}
	// Do not install the shadow border when the contents
	// has a preferred size less than or equal to 0.
	// We can't use the size, because it is(0, 0) for new popups.
	final Dimension contentsPrefSize = newContents.getPreferredSize();
	if (contentsPrefSize.width <= 0 || contentsPrefSize.height <= 0) {
		return;
	}
	for (Container p = newContents.getParent(); p != null; p = p.getParent()) {
		if (p instanceof JWindow || p instanceof Panel) {
			// Workaround for the gray rect problem.
			p.setBackground(newContents.getBackground());
			heavyWeightContainer = p;
			break;
		}
	}
	final JComponent parent = (JComponent) newContents.getParent();
	oldOpaque = parent.isOpaque();
	oldBorder = parent.getBorder();
	parent.setOpaque(false);
	parent.setBorder(SHADOW_BORDER);
	// Pack it because we have changed the border.
	if (heavyWeightContainer != null) {
		heavyWeightContainer.setSize(heavyWeightContainer.getPreferredSize());
	} else {
		parent.setSize(parent.getPreferredSize());
	}
}
 
源代码17 项目: netbeans   文件: MenuBar.java
private Component createNoComponent() {
    JComponent noComponent = new JComponent() {};
    noComponent.setSize(0, 0);
    noComponent.setVisible(false);
    return noComponent;
}
 
源代码18 项目: PolyGlot   文件: PToolTipUI.java
/**
 * To override font, override createToolTip() on component creating tooltip.
 * On creation of ToolTip, change to desired font.
 * @param g
 * @param c 
 */
@Override
public void paint(Graphics g, JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    tipText = tipText == null ? "" : tipText;
    String[] tipLines = tipText.split("\n");
    Font font = c.getFont();
    
    g.setFont(font);
    
    FontMetrics metrics = g.getFontMetrics();
    int fontHeight = metrics.getHeight();
    int height = (fontHeight * tipLines.length) + 2;
    int width = this.getWidestStringText(tipLines, metrics) + 10;
    
    int fontSize = font.getSize();
    fontSize = fontSize == 0 ? PGTUtil.DEFAULT_FONT_SIZE.intValue() : fontSize;
    c.setFont(font.deriveFont(fontSize));
    ((JToolTip)c).setTipText(tipText);
    
    
    Dimension size = new Dimension(width, height);
    
    c.setSize(size);
    c.getParent().setSize(size);
    
    Insets insets = c.getInsets();
    Rectangle paintTextR = new Rectangle(
        insets.left,
        insets.top,
        size.width - (insets.left + insets.right),
        size.height - (insets.top + insets.bottom));
    
    ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    
    g.setColor(Color.black);
    g.fillRect(insets.left,
        insets.top,
        size.width - (insets.left + insets.right),
        size.height - (insets.top + insets.bottom));
    
    g.setColor(Color.white);
    
    for (int i = 0 ; i < tipLines.length; i++) {
        g.drawString(tipLines[i], paintTextR.x + 5,
                paintTextR.y + metrics.getAscent() + (i * (fontHeight)));
    }
}