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

The following are Jave code examples for showing how to use getWidth() 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: SplitLayerUI.java   View Source Code Vote up 6 votes
@Override
public void paint( Graphics g, JComponent c ) {
    super.paint( g, c ); //To change body of generated methods, choose Tools | Templates.
    if( null != lastLocation && isDragging ) {
        Rectangle rect = new Rectangle();
        if( horizontalSplit ) {
            rect.width = splitterWidth;
            rect.height = c.getHeight();
            rect.x = lastLocation.x;
        } else {
            rect.width = c.getWidth();
            rect.height = splitterWidth;
            rect.y = lastLocation.y;
        }
        g.setColor( FILL_COLOR );
        g.fillRect( rect.x, rect.y, rect.width, rect.height );
    }
}
 
Example 2
Project: incubator-netbeans   File: AbstractViewTabDisplayerUI.java   View Source Code Vote up 6 votes
/**
 * Paint the background when using non-stretching tabs.
 * @param g
 * @param c 
 * @since 1.27
 */
protected void paintDisplayerBackground( Graphics g, JComponent c ) {
    int x;
    int width;
    if( !isUseStretchingTabs() ) {
        x = 0;
        width = c.getWidth();
        if( dataModel.size() > 0 ) {
            x += layoutModel.getX( dataModel.size()-1 );
            x += layoutModel.getW( dataModel.size()-1 )-1;
            width -= x;
        }
        paintTabBackground( g, -1, x, 0, width, c.getHeight());
        paintTabBorder( g, -1, x, 0, width, c.getHeight());
    }
}
 
Example 3
Project: incubator-netbeans   File: TabListPopupAction.java   View Source Code Vote up 6 votes
@Override
public void actionPerformed(ActionEvent ae) {
    if ("pressed".equals(ae.getActionCommand())) { //NOI18N
        JComponent jc = (JComponent) ae.getSource();
        Point p = new Point(jc.getWidth(), jc.getHeight());
        SwingUtilities.convertPointToScreen(p, jc);
        if (!ButtonPopupSwitcher.isShown()) {
            ButtonPopupSwitcher.showPopup(jc, displayer, p.x, p.y);
        } else {
            ButtonPopupSwitcher.hidePopup();
        }
        //Other portion of issue 37487, looks funny if the
        //button becomes pressed
        if (jc instanceof AbstractButton) {
            AbstractButton jb = (AbstractButton) jc;
            jb.getModel().setPressed(false);
            jb.getModel().setRollover(false);
            jb.getModel().setArmed(false);
            jb.repaint();
        }
    }
}
 
Example 4
Project: incubator-netbeans   File: TabListPopupAction.java   View Source Code Vote up 6 votes
@Override
public void actionPerformed( ActionEvent ae ) {
    if ("pressed".equals(ae.getActionCommand())) { //NOI18N
        JComponent jc = (JComponent) ae.getSource();
        Point p = new Point(jc.getWidth(), jc.getHeight());
        SwingUtilities.convertPointToScreen(p, jc);
        if (!ButtonPopupSwitcher.isShown()) {
            ButtonPopupSwitcher.showPopup(jc, controller, p.x, p.y);
        } else {
            ButtonPopupSwitcher.hidePopup();
        }
        //Other portion of issue 37487, looks funny if the
        //button becomes pressed
        if (jc instanceof AbstractButton) {
            AbstractButton jb = (AbstractButton) jc;
            jb.getModel().setPressed(false);
            jb.getModel().setRollover(false);
            jb.getModel().setArmed(false);
            jb.repaint();
        }
    }
}
 
Example 5
Project: rapidminer   File: ButtonUI.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	if (RapidLookTools.isToolbarButton(b)) {
		RapidLookTools.drawToolbarButton(g, b);
		super.paint(g, c);
		return;
	}

	int w = c.getWidth();
	int h = c.getHeight();
	if (w <= 0 || h <= 0) {
		return;
	}

	if (b.isContentAreaFilled()) {
		RapidLookTools.drawButton(b, g, RapidLookTools.createShapeForButton(b));
	}
	if (b.isBorderPainted()) {
		RapidLookTools.drawButtonBorder(b, g, RapidLookTools.createBorderShapeForButton(b));
	}
	super.paint(g, c);
}
 
Example 6
Project: rapidminer   File: ComboBoxUI.java   View Source Code Vote up 6 votes
/**
 * Draws the border of the combobox.
 */
private void paintBorder(Graphics g, JComponent c) {
	int w = c.getWidth();
	int h = c.getHeight();
	if (w <= 0 || h <= 0) {
		return;
	}

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	boolean hasFocus = comboBox.isEditable() ? c.isFocusOwner()
			|| ((JComboBox) c).getEditor().getEditorComponent().isFocusOwner() : c.isFocusOwner();
			if (c.isEnabled()) {
				if (hasFocus) {
					g2.setColor(Colors.COMBOBOX_BORDER_FOCUS);
				} else {
					g2.setColor(Colors.COMBOBOX_BORDER);
				}
			} else {
				g2.setColor(Colors.COMBOBOX_BORDER_DISABLED);
			}

			g2.drawRoundRect(0, 0, w - 1, h - 1, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
}
 
Example 7
Project: incubator-netbeans   File: ComponentProvider.java   View Source Code Vote up 5 votes
public PrintPage[][] getPages(int pageWidth, int pageHeight, double pageZoom) {
    List<ComponentPage> pages = new ArrayList<ComponentPage>();
    JComponent component = getComponent();

    if (component == null) {
        return new PrintPage[0][0];
    }
    int componentWidth = component.getWidth();
    int componentHeight = component.getHeight();

    double zoom = getZoom(pageZoom, pageWidth, pageHeight, componentWidth, componentHeight);

    componentWidth = (int) Math.floor(componentWidth * zoom);
    componentHeight = (int) Math.floor(componentHeight * zoom);

    int row = 0;
    int column = 0;

    for (int h = 0; h < componentHeight; h += pageHeight) {
        row++;
        column = 0;

        for (int w = 0; w < componentWidth; w += pageWidth) {
            column++;
            Rectangle piece = new Rectangle((column - 1) * pageWidth, (row - 1) * pageHeight, pageWidth, pageHeight);
            pages.add(new ComponentPage(component, piece, zoom, row - 1, column - 1));
        }
    }
    PrintPage[][] printPages = new PrintPage[row][column];

    for (ComponentPage page : pages) {
        printPages[page.getRow()][page.getColumn()] = page;
    }
    return printPages;
}
 
Example 8
Project: OpenJSharp   File: SynthToggleButtonUI.java   View Source Code Vote up 5 votes
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) {
    if (((AbstractButton) c).isContentAreaFilled()) {
        int x = 0, y = 0, w = c.getWidth(), h = c.getHeight();
        SynthPainter painter = context.getPainter();
        painter.paintToggleButtonBackground(context, g, x, y, w, h);
    }
}
 
Example 9
Project: incubator-netbeans   File: NimbusEditorTabCellRenderer.java   View Source Code Vote up 5 votes
private void paintCloseButton(Graphics g, JComponent c) {
    if (((AbstractTabCellRenderer) c).isShowCloseButton()) {
        
        Rectangle r = new Rectangle(0, 0, c.getWidth(), c.getHeight());
        Rectangle cbRect = new Rectangle();
        getCloseButtonRectangle((JComponent) c, cbRect, r);
        
        //paint close button
        String iconPath = findIconPath( (NimbusEditorTabCellRenderer)c  );
        Icon icon = TabControlButtonFactory.getIcon( iconPath );
        icon.paintIcon(c, g, cbRect.x, cbRect.y);
    }
}
 
Example 10
Project: incubator-netbeans   File: AbstractViewTabDisplayerUI.java   View Source Code Vote up 5 votes
@Override
public Polygon getInsertTabIndication(int index) {
    EqualPolygon indication = new EqualPolygon();
    JComponent control = getDisplayer();
    int height = control.getHeight();
    int width = control.getWidth();
    TabLayoutModel tlm = getLayoutModel();

    int tabXStart;
    int tabXEnd;
    if (index == 0) {
        tabXStart = 0;
        tabXEnd = tlm.getW(0) / 2;
    } else if (index >= getDataModel().size()) {
        tabXStart = tlm.getX(index - 1) + tlm.getW(index - 1) / 2;
        tabXEnd = tabXStart + tlm.getW(index - 1);
        if (tabXEnd > width) {
            tabXEnd = width;
        }
    } else {
        tabXStart = tlm.getX(index - 1) + tlm.getW(index - 1) / 2;
        tabXEnd = tlm.getX(index) + tlm.getW(index) / 2;
    }

    indication.moveTo(tabXStart, 0);
    indication.lineTo(tabXEnd, 0);
    indication.lineTo(tabXEnd, height - 1);
    indication.lineTo(tabXStart, height - 1);
    return indication;
}
 
Example 11
Project: incubator-netbeans   File: ButtonPopupSwitcher.java   View Source Code Vote up 5 votes
/** Creates a new instance of TabListPanel */
private ButtonPopupSwitcher(JComponent owner, SwitcherTableItem items[], int x, int y) {
    int ownerWidth = owner.getWidth();
    int ownerHeight = owner.getHeight();
    int cornerX, cornerY;
    int xOrient, yOrient;
    Rectangle screenRect = Utilities.getUsableScreenBounds();

    // get rid of the effect when popup seems to be higher that screen height
    int gap = (y == 0 ? 10 : 5);
    int height = 0;
    int width = 0;

    int leftD = x - screenRect.x;
    int rightD = screenRect.x + screenRect.width - x;
    if (leftD < rightD / 2) {
        xOrient = 1;
        width = rightD;
        cornerX = x + 1;
    } else {
        xOrient = -1;
        width = leftD + ownerWidth;
        cornerX = x + ownerWidth;
    }
    int topD = y - screenRect.y;
    int bottomD = screenRect.y + screenRect.height - y;
    if (bottomD < topD / 4) {
        yOrient = -1;
        height = topD - gap;
        cornerY = y;
    } else {
        yOrient = 1;
        cornerY = y + ownerHeight;
        height = screenRect.height - cornerY - gap;
    }

    this.pTable = new SwitcherTable(items, height, width);
    this.x = cornerX - (xOrient == -1 ? (int) pTable.getPreferredSize().getWidth() : 0);
    this.y = cornerY - (yOrient == -1 ? (int) pTable.getPreferredSize().getHeight() : 0);
}
 
Example 12
Project: FreeCol   File: ImageLibrary.java   View Source Code Vote up 5 votes
/**
 * Draw a (usually small) background image into a (usually larger)
 * space specified by a component, tiling the image to fill up the
 * space.  If the image is not available, just fill with the background
 * colour.
 *
 * @param resource The name of the {@code ImageResource} to tile with.
 * @param g The {@code Graphics} to draw to.
 * @param c The {@code JComponent} that defines the space.
 * @param insets Optional {@code Insets} to apply.
 */
public static void drawTiledImage(String resource, Graphics g,
                                  JComponent c, Insets insets) {
    int width = c.getWidth();
    int height = c.getHeight();
    int xmin, ymin;
    if (insets == null) {
        xmin = 0;
        ymin = 0;
    } else {
        xmin = insets.left;
        ymin = insets.top;
        width -= insets.left + insets.right;
        height -= insets.top + insets.bottom;
    }

    if (ResourceManager.hasImageResource(resource)) {
        BufferedImage image = ResourceManager.getImage(resource);
        // FIXME: Test and profile if calling fillTexture is better.
        int dx = image.getWidth();
        int dy = image.getHeight();
        int xmax = xmin + width;
        int ymax = ymin + height;
        for (int x = xmin; x < xmax; x += dx) {
            for (int y = ymin; y < ymax; y += dy) {
                g.drawImage(image, x, y, null);
            }
        }
    } else {
        g.setColor(c.getBackground());
        g.fillRect(xmin, ymin, width, height);
    }
}
 
Example 13
Project: jdk8u-jdk   File: SynthToggleButtonUI.java   View Source Code Vote up 5 votes
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) {
    if (((AbstractButton) c).isContentAreaFilled()) {
        int x = 0, y = 0, w = c.getWidth(), h = c.getHeight();
        SynthPainter painter = context.getPainter();
        painter.paintToggleButtonBackground(context, g, x, y, w, h);
    }
}
 
Example 14
Project: openjdk-jdk10   File: SynthToggleButtonUI.java   View Source Code Vote up 5 votes
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) {
    if (((AbstractButton) c).isContentAreaFilled()) {
        int x = 0, y = 0, w = c.getWidth(), h = c.getHeight();
        SynthPainter painter = context.getPainter();
        painter.paintToggleButtonBackground(context, g, x, y, w, h);
    }
}
 
Example 15
Project: incubator-netbeans   File: DropTargetLayer.java   View Source Code Vote up 4 votes
public static boolean isMenuRightEdge(Point pt, JComponent menu) {
    return pt.x > menu.getWidth()-8;
}
 
Example 16
Project: incubator-netbeans   File: DropTargetLayer.java   View Source Code Vote up 4 votes
public static boolean isSubMenuRightEdge(Point pt, JComponent menu) {
    return pt.x > menu.getWidth()-30;
}
 
Example 17
Project: faitic-checker   File: CustomScrollBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {

	boolean isVertical=c.getWidth()<c.getHeight();
	
	int barwidth=isVertical ? thumbBounds.width/2 : thumbBounds.height/2;
	
	Graphics2D g2=(Graphics2D) g;
	
 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
	g2.setColor(fore);
	
	if(isVertical)
		g2.fillRoundRect(thumbBounds.x+barwidth/2, thumbBounds.y, barwidth, thumbBounds.height, barwidth,barwidth);
	else
		g2.fillRoundRect(thumbBounds.x, thumbBounds.y+barwidth/2, thumbBounds.width, barwidth, barwidth,barwidth);
	
}
 
Example 18
Project: incubator-netbeans   File: ToolTipManagerEx.java   View Source Code Vote up 4 votes
private void initiateToolTip(MouseEvent event) {
       if (event.getSource() == window) {
           return;
       }
       JComponent component = (JComponent)event.getSource();
component.removeMouseMotionListener(moveBeforeEnterListener);

       exitTimer.stop();

Point location = event.getPoint();
// ensure tooltip shows only in proper place
if (location.x < 0 || 
    location.x >=component.getWidth() ||
    location.y < 0 ||
    location.y >= component.getHeight()) {
    return;
}

       if (insideComponent != null) {
           enterTimer.stop();
       }
// A component in an unactive internal frame is sent two
// mouseEntered events, make sure we don't end up adding
// ourselves an extra time.
       component.removeMouseMotionListener(this);
       component.addMouseMotionListener(this);

       boolean sameComponent = (insideComponent == component);

       insideComponent = component;
if (tipWindow != null){
           mouseEvent = event;
           if (showImmediately) {
               Rectangle rect = provider.getToolTipSourceBounds( event.getPoint() );
               if( null != rect ) {
                   String newToolTipText = startToolTipCalculation( rect, event.getPoint() );

                   if (!sameComponent || !toolTipText.equals(newToolTipText) /*|| 
                            !sameLoc*/) {
                       toolTipText = newToolTipText;
                       showTipWindow();
                   }
               }
           } else {
               enterTimer.start();
           }
       }
   }
 
Example 19
Project: faitic-checker   File: CustomScrollBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
	
	boolean isVertical=c.getWidth()<c.getHeight();
	
	g.setColor(back);
	g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);

	int barwidth=isVertical ? trackBounds.width/2 : trackBounds.height/2;
	
	Graphics2D g2=(Graphics2D) g;
	
 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
	g2.setColor(forenobar);
	
	if(isVertical)
		g2.fillRoundRect(trackBounds.x+barwidth/2, trackBounds.y, barwidth, trackBounds.height, barwidth,barwidth);
	else
		g2.fillRoundRect(trackBounds.x, trackBounds.y+barwidth/2, trackBounds.width, barwidth, barwidth,barwidth);

}
 
Example 20
Project: rapidminer   File: ComboBoxUI.java   View Source Code Vote up 4 votes
/**
 * Draws the combobox itself.
 */
private void paintBox(Graphics g, JComponent c) {
	int w = c.getWidth();
	int h = c.getHeight() - 1;
	if (w <= 0 || h <= 0) {
		return;
	}

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (c.isEnabled()) {
		if (Boolean.parseBoolean(String.valueOf(c.getClientProperty(RapidLookTools.PROPERTY_INPUT_BACKGROUND_DARK)))) {
			g2.setColor(Colors.COMBOBOX_BACKGROUND_DARK);
		} else {
			g2.setColor(Colors.COMBOBOX_BACKGROUND);
		}
	} else {
		g2.setColor(Colors.COMBOBOX_BACKGROUND_DISABLED);
	}

	g2.fillRoundRect(0, 0, w - 1, h, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	// arrow
	int ny = c.getSize().height / 2 - 3;
	int nx = c.getWidth() - 15;

	if (isDown && c.isEnabled()) {
		nx++;
		ny++;
	}
	g2.translate(nx, ny);

	if (c.isEnabled()) {
		g2.setColor(Colors.COMBOBOX_ARROW);
	} else {
		g2.setColor(Colors.COMBOBOX_ARROW_DISABLED);
	}

	w = 14;
	Polygon arrow = new Polygon(new int[] { 0, 4, 8 }, new int[] { 0, 6, 0 }, 3);
	g2.fillPolygon(arrow);

	g2.translate(-nx, -ny);
}