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

The following are Jave code examples for showing how to use setSize() 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: SystemAction.java   View Source Code Vote up 6 votes
/** 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));
}
 
Example 2
Project: incubator-netbeans   File: HideableBarRenderer.java   View Source Code Vote up 6 votes
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);
    
    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);
    }
}
 
Example 3
Project: incubator-netbeans   File: ComponentMorpher2.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: HBaseClient   File: AppFrame.java   View Source Code Vote up 6 votes
/**
 * 初始化主窗口信息
 */
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("欢迎使用!");
}
 
Example 5
Project: incubator-netbeans   File: PalettePanel.java   View Source Code Vote up 5 votes
@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();
    }
}
 
Example 6
Project: incubator-netbeans   File: ComponentMorpher.java   View Source Code Vote up 5 votes
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;
}
 
Example 7
Project: rapidminer   File: PlotterAdapter.java   View Source Code Vote up 5 votes
@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);
}
 
Example 8
Project: openjdk-jdk10   File: bug8132119.java   View Source Code Vote up 5 votes
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;
}
 
Example 9
Project: incubator-netbeans   File: MenuBar.java   View Source Code Vote up 4 votes
private Component createNoComponent() {
    JComponent noComponent = new JComponent() {};
    noComponent.setSize(0, 0);
    noComponent.setVisible(false);
    return noComponent;
}