javax.swing.JComponent.getWidth()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中javax.swing.JComponent.getWidth()方法的一些代码示例,展示了JComponent.getWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.getWidth()方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:getWidth

JComponent.getWidth介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
double xScale = ((double) getWidth() - 2 * BORDER_GAP) / (scores.size() - 1);
double yScale = ((double) getHeight() - 2 * BORDER_GAP) / (MAX_SCORE - 1);
g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, BORDER_GAP, BORDER_GAP);
g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, getWidth() - BORDER_GAP, getHeight() - BORDER_GAP);
  int x0 = (i + 1) * (getWidth() - BORDER_GAP * 2) / (scores.size() - 1) + BORDER_GAP;
  int x1 = x0;
  int y0 = getHeight() - BORDER_GAP;
return new Dimension(PREF_W, PREF_H);
JFrame frame = new JFrame("DrawGraph");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

constraints.fill = GridBagConstraints.BOTH;
JLabel l = new JLabel("You have got 2 new Messages.");
panel.add(l, constraints);
constraints.gridx++;
constraints.weightx = 0f;
b.setMargin(new Insets(1, 4, 1, 4));
b.setFocusable(false);
panel.add(b, constraints);
dialog.setUndecorated(true);
dialog.setSize(300, 100);
  final Graphics2D g2d = (Graphics2D) g;
  g2d.setPaint(lpg);
  g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
  g2d.setColor(Color.BLACK);
  g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);

代码示例来源:origin: stackoverflow.com

g.clipRect(insets.left, insets.top, getWidth(), getHeight() - insets.top - insets.bottom);
super.paintChildren(g);
  int height = heightMargin + extent;
  setPopupSize(new Dimension(width, height));
  Dimension dim = new Dimension();
  for(Component comp :parent.getComponents()){
    if(comp.isVisible()) {
  Dimension dim = new Dimension();
  for(Component comp : parent.getComponents()) {
    if(comp.isVisible()){

代码示例来源:origin: stackoverflow.com

super.paintComponent(g);
if (this.isLiving) {
  g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
} else {
  g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
  for (int jj = 0; jj < s; jj++) {
    GameOfLife cell = new GameOfLife(ii, jj);
    cell.setPreferredSize(new Dimension(10, 10));
    gui.add(cell);
    biosphere[ii][jj] = cell;

代码示例来源:origin: winder/Universal-G-Code-Sender

/**
 * Compare current dimensions with those representing nominal thresholds.
 */
private void determineNominalSize() {
  int previousSize = currentSize;
  currentSize = 0;
  int width = component.getWidth();
  int height = component.getHeight();
  // increment size for each threshold exceeded
  dimensions.forEach(dimension -> {
    if (width > dimension.width && height > dimension.height) currentSize++;
  });
  if (previousSize != currentSize) fireSizeChanged(currentSize);
}

代码示例来源:origin: stackoverflow.com

g.drawString(s, getWidth() / 2 - g.getFontMetrics().stringWidth(s) / 2,
    getHeight() / 2 + g.getFontMetrics().getHeight() / 2);
JFrame f = new JFrame();
f.setSize(500, 500);
f.setTitle("Sometimes Red, Sometimes Blue");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new TestPanel());
f.setVisible(true);

代码示例来源:origin: stackoverflow.com

import javax.swing.*;
import java.awt.image.*;
import java.awt.*;

public class PictureFrame extends JComponent{

  private final Image img;

  public PictureFrame(final String file) throws IOException {
    this(new File(file));
  }

  public PictureFrame(final File file) throws IOException {
    this(ImageIO.read(file));
  }

  public PictureFrame(BufferedImage img){
    this.img = img;
    this.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));
  }

  public void paintComponent(Graphics g){
    super.paintComponent(g);

    g.drawImage(img, 0, 0, getWidth(), getHeight(), null);
  }
}

代码示例来源:origin: stackoverflow.com

g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
g2d.setColor(Color.BLACK);
g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
 l.setOpaque(false);
 c.add(l, constraints);
 b.setFocusable(false);
 c.add(b, constraints);

代码示例来源:origin: ron190/jsql-injection

int diff = this.component.getHeight() - parentHeight;
int diff = this.component.getWidth() - parentWidth;

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Testing");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new TestPane());
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
    Point point = e.getPoint();
    int width = getWidth();
    int height = getHeight();
return new Dimension(200, 200);
Graphics2D g2d = (Graphics2D) g.create();
int width = getWidth();
int height = getHeight();

代码示例来源:origin: stackoverflow.com

l.setBackground(bg);
l.setOpaque(true);
c.add(l);
  l.setBackground(bg);
  l.setOpaque(true);
  c.add(l);
    if (result == JOptionPane.OK_OPTION) {
      BufferedImage bi = new BufferedImage(
          tileSet.getWidth(),
          tileSet.getHeight(),
          BufferedImage.TYPE_INT_ARGB);
      Graphics g = bi.createGraphics();

代码示例来源:origin: ron190/jsql-injection

/**
 *  In this case a real component is to be painted. Setting the location
 *  of the component will cause it to be painted at that location.
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  
  float x2 =
    ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
    ? (0 + this.component.getWidth()) * this.component.getAlignmentX() + x
    : (width - this.component.getWidth()) * this.component.getAlignmentX() + x;
  float y2 = (height - this.component.getHeight()) * this.component.getAlignmentY() + y;
  this.component.setLocation((int) x2 + this.addX, (int) y2 + this.addY);
}

代码示例来源:origin: stackoverflow.com

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
double xScale = ((double) getWidth() - (2 * padding) - labelPadding) / (scores.size() - 1);
double yScale = ((double) getHeight() - 2 * padding - labelPadding) / (getMaxScore() - getMinScore());
g2.fillRect(padding + labelPadding, padding, getWidth() - (2 * padding) - labelPadding, getHeight() - 2 * padding - labelPadding);
g2.setColor(Color.BLACK);
  int x0 = padding + labelPadding;
  int x1 = pointWidth + padding + labelPadding;
  int y0 = getHeight() - ((i * (getHeight() - padding * 2 - labelPadding)) / numberYDivisions + padding + labelPadding);
  int y1 = y0;
  if (scores.size() > 0) {
    g2.setColor(gridColor);
    g2.drawLine(padding + labelPadding + 1 + pointWidth, y0, getWidth() - padding, y1);
    g2.setColor(Color.BLACK);
    String yLabel = ((int) ((getMinScore() + (getMaxScore() - getMinScore()) * ((i * 1.0) / numberYDivisions)) * 100)) / 100.0 + "";
    int x0 = i * (getWidth() - padding * 2 - labelPadding) / (scores.size() - 1) + padding + labelPadding;
    int x1 = x0;
    int y0 = getHeight() - padding - labelPadding;
g2.drawLine(padding + labelPadding, getHeight() - padding - labelPadding, padding + labelPadding, padding);
g2.drawLine(padding + labelPadding, getHeight() - padding - labelPadding, getWidth() - padding, getHeight() - padding - labelPadding);

代码示例来源:origin: magefree/mage

@Override
  public void componentResized(ComponentEvent e) {
    int width = ((JComponent) e.getSource()).getWidth();
    int height = ((JComponent) e.getSource()).getHeight();
    SettingsManager.instance.setScreenWidthAndHeight(width, height);
    if (!liteMode && !grayMode) {
      backgroundPane.setSize(width, height);
    }
    updateCurrentFrameSize();
    ArrowBuilder.getBuilder().setSize(width, height);
    if (title != null) {
      title.setBounds((int) (width - titleRectangle.getWidth()) / 2, (int) (height - titleRectangle.getHeight()) / 2, titleRectangle.width, titleRectangle.height);
    }
  }
});

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame();
    frame.setLayout(new GridLayout(N, N, N, N));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    for (int i = 0; i < N * N; i++) {
      frame.add(new RotatePanel());
    frame.setVisible(true);
this.setPreferredSize(new Dimension(
  image.getWidth(null), image.getHeight(null)));
this.addMouseListener(new MouseAdapter() {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.translate(this.getWidth() / 2, this.getHeight() / 2);
g2d.rotate(theta);
g2d.translate(-image.getWidth(this) / 2, -image.getHeight(this) / 2);
return new Dimension(SIZE, SIZE);

代码示例来源:origin: magefree/mage

@Override
  public void componentResized(ComponentEvent e) {
    int width = ((JComponent) e.getSource()).getWidth();
    int height = ((JComponent) e.getSource()).getHeight();
    jLayeredBackgroundPane.setSize(width, height);
    jSplitPane0.setSize(width, height);
    if (height < storedHeight) {
      pnlBattlefield.setSize(0, 200);
    }
    storedHeight = height;
    sizeToScreen();
    if (!initialized) {
      String state = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BIG_CARD_TOGGLED, null);
      if (state != null && state.equals("down")) {
        jSplitPane0.setDividerLocation(1.0);
      }
      initialized = true;
    }
  }
});

代码示例来源:origin: stackoverflow.com

super(true);
this.setOpaque(false);
this.setPreferredSize(new Dimension(WIDE, HIGH));
this.addMouseListener(new MouseHandler());
this.addComponentListener(new ComponentHandler());
long start = System.nanoTime();
super.paintComponent(g);
int w = this.getWidth();
int h = this.getHeight();
g.drawImage(background, 0, 0, this);
double theta = 2 * Math.PI * index++ / 64;
  Dimension d = field.getPreferredSize();
  field.setBounds(e.getX(), e.getY(), d.width, d.height);
  add(field);
public void componentResized(ComponentEvent e) {
  super.componentResized(e);
  int w = getWidth();
  int h = getHeight();
  background = gc.createCompatibleImage(w, h, Transparency.OPAQUE);
  Graphics2D g = background.createGraphics();

代码示例来源:origin: stackoverflow.com

int w = displayWidth != 0 ? displayWidth - 1 : getWidth() - 1;
int h = displayHeight != 0 ? displayHeight - 1 : getHeight() - 1;
  g2d.fillRect(0, 0, getWidth(), getHeight());
int w = getWidth();
int h = getHeight();

代码示例来源:origin: stackoverflow.com

g2d.setStroke(basicStroke);
int archH =  (getHeight()-4)/2;
g2d.drawRoundRect(3, 3, getWidth()-4, getHeight()-4, archH, archH);
  g2d.fillRoundRect(3, 3, getWidth()-4, getHeight()-4, archH, archH);
  setForeground(Color.black);
add(usrNameLabel, labCnst);
add(usrNameFeild, txtCnst);
g2d.fillRect(0, 0, getWidth(), getHeight());
g2d.drawImage(gradientImage, 0, 0, getWidth(), getHeight(), this);
g2d.dispose();
BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
  LinearGradientPaint lgrPaint =  new LinearGradientPaint(0.0f, 0.0f, getWidth(), getHeight(),
                            new float[] { 0.0f, 0.5f, 0.6f, 1.0f },
                            new Color[] { new Color(0x002AFF),
  g2d.setPaint(lgrPaint);
  g2d.fillRect(0, 0, getWidth(), getHeight());
    JFrame frame = new JFrame("Demo: LogIn Dialogue");

代码示例来源:origin: org.netbeans.api/org-openide-awt

g.fillRect(x, 0, c.getWidth() - x, c.getHeight());
  g.drawRect(x, 0, c.getWidth() - (x + 1), c.getHeight() - 1);

相关文章

JComponent类方法