本文整理匯總了Java中javax.swing.JComponent.getWidth方法的典型用法代碼示例。如果您正苦於以下問題:Java JComponent.getWidth方法的具體用法?Java JComponent.getWidth怎麽用?Java JComponent.getWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JComponent
的用法示例。
在下文中一共展示了JComponent.getWidth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: paint
import javax.swing.JComponent; //導入方法依賴的package包/類
@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 );
}
}
示例2: paintDisplayerBackground
import javax.swing.JComponent; //導入方法依賴的package包/類
/**
* 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());
}
}
示例3: actionPerformed
import javax.swing.JComponent; //導入方法依賴的package包/類
@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();
}
}
}
示例4: actionPerformed
import javax.swing.JComponent; //導入方法依賴的package包/類
@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();
}
}
}
示例5: paint
import javax.swing.JComponent; //導入方法依賴的package包/類
@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);
}
示例6: paintBorder
import javax.swing.JComponent; //導入方法依賴的package包/類
/**
* 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);
}
示例7: getPages
import javax.swing.JComponent; //導入方法依賴的package包/類
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;
}
示例8: paintBackground
import javax.swing.JComponent; //導入方法依賴的package包/類
@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);
}
}
示例9: paintCloseButton
import javax.swing.JComponent; //導入方法依賴的package包/類
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);
}
}
示例10: getInsertTabIndication
import javax.swing.JComponent; //導入方法依賴的package包/類
@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;
}
示例11: ButtonPopupSwitcher
import javax.swing.JComponent; //導入方法依賴的package包/類
/** 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);
}
示例12: drawTiledImage
import javax.swing.JComponent; //導入方法依賴的package包/類
/**
* 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);
}
}
示例13: isMenuRightEdge
import javax.swing.JComponent; //導入方法依賴的package包/類
public static boolean isMenuRightEdge(Point pt, JComponent menu) {
return pt.x > menu.getWidth()-8;
}
示例14: isSubMenuRightEdge
import javax.swing.JComponent; //導入方法依賴的package包/類
public static boolean isSubMenuRightEdge(Point pt, JComponent menu) {
return pt.x > menu.getWidth()-30;
}
示例15: paintThumb
import javax.swing.JComponent; //導入方法依賴的package包/類
@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);
}