javax.swing.JButton.getPreferredSize()方法的使用及代码示例

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

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

JButton.getPreferredSize介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

new Dimension(0, Math.max(nameLabel.getPreferredSize().height, deleteButton.getPreferredSize().height)));
add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(5, 0, 0, 5), 0, 0));

代码示例来源:origin: libgdx/libgdx

new Dimension(0, Math.max(nameLabel.getPreferredSize().height, deleteButton.getPreferredSize().height)));
add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  new Insets(5, 0, 0, 5), 0, 0));

代码示例来源:origin: libgdx/libgdx

public void layoutContainer (Container parent) {
  Dimension buttonSize = upButton.getPreferredSize();
  int upButtonX = getWidth() - buttonSize.width * 3 - 6 - 5;
  upButton.setBounds(upButtonX, 0, buttonSize.width, buttonSize.height);
  downButton.setBounds(getWidth() - buttonSize.width * 2 - 3 - 5, 0, buttonSize.width, buttonSize.height);
  deleteButton.setBounds(getWidth() - buttonSize.width - 5, 0, buttonSize.width, buttonSize.height);
  Dimension labelSize = nameLabel.getPreferredSize();
  nameLabel.setBounds(5, buttonSize.height / 2 - labelSize.height / 2, getWidth() - 5, labelSize.height);
}

代码示例来源:origin: libgdx/libgdx

public void layoutContainer (Container parent) {
  Dimension buttonSize = upButton.getPreferredSize();
  int upButtonX = getWidth() - buttonSize.width * 3 - 6 - 5;
  upButton.setBounds(upButtonX, 0, buttonSize.width, buttonSize.height);
  downButton.setBounds(getWidth() - buttonSize.width * 2 - 3 - 5, 0, buttonSize.width, buttonSize.height);
  deleteButton.setBounds(getWidth() - buttonSize.width - 5, 0, buttonSize.width, buttonSize.height);
  Dimension labelSize = nameLabel.getPreferredSize();
  nameLabel.setBounds(5, buttonSize.height / 2 - labelSize.height / 2, getWidth() - 5, labelSize.height);
}

代码示例来源:origin: kiegroup/optaplanner

solvePanel.add(terminateSolvingEarlyButton, "terminateSolvingEarlyAction");
solveButton.setMinimumSize(terminateSolvingEarlyButton.getMinimumSize());
solveButton.setPreferredSize(terminateSolvingEarlyButton.getPreferredSize());

代码示例来源:origin: groovy/groovy-core

REPLACE_ALL_BUTTON.getPreferredSize() :
    REPLACE_BUTTON.getPreferredSize();
FIND_BUTTON.setPreferredSize(d);
REPLACE_BUTTON.setPreferredSize(d);

代码示例来源:origin: kiegroup/optaplanner

private void defineGrid(ScrabbleSolution solution) {
  JButton footprint = SwingUtils.makeSmallButton(new JButton("99"));
  int footprintWidth = footprint.getPreferredSize().width;
  gridPanel.defineColumnHeaderByKey(HEADER_COLUMN);
  for (int x = 0; x < solution.getGridWidth(); x++) {
    gridPanel.defineColumnHeader(x, footprintWidth);
  }
  gridPanel.defineRowHeaderByKey(HEADER_ROW);
  for (int y = 0; y < solution.getGridHeight(); y++) {
    gridPanel.defineRowHeader(y);
  }
  gridPanel.defineRowHeader(null); // Unassigned
}

代码示例来源:origin: kiegroup/optaplanner

private void defineGrid(TravelingTournament travelingTournament) {
  JButton footprint = SwingUtils.makeSmallButton(new JButton("MMMMM"));
  int footprintWidth = footprint.getPreferredSize().width;
  teamsPanel.defineColumnHeaderByKey(HEADER_COLUMN); // Day header
  for (Team team : travelingTournament.getTeamList()) {
    teamsPanel.defineColumnHeader(team, footprintWidth);
  }
  teamsPanel.defineColumnHeader(null, footprintWidth); // Unassigned
  teamsPanel.defineRowHeaderByKey(HEADER_ROW); // Team header
  for (Day day : travelingTournament.getDayList()) {
    teamsPanel.defineRowHeader(day);
  }
  teamsPanel.defineRowHeader(null); // Unassigned day
}

代码示例来源:origin: kiegroup/optaplanner

private void defineGrid(Examination examination) {
  JButton footprint = SwingUtils.makeSmallButton(new JButton("99999999"));
  int footprintWidth = footprint.getPreferredSize().width;
  roomsPanel.defineColumnHeaderByKey(HEADER_COLUMN); // Period header
  for (Room room : examination.getRoomList()) {
    roomsPanel.defineColumnHeader(room, footprintWidth);
  }
  roomsPanel.defineColumnHeader(null, footprintWidth); // Unassigned
  roomsPanel.defineRowHeaderByKey(HEADER_ROW); // Room header
  for (Period period : examination.getPeriodList()) {
    roomsPanel.defineRowHeader(period);
  }
  roomsPanel.defineRowHeader(null); // Unassigned period
}

代码示例来源:origin: kiegroup/optaplanner

private void defineGrid(PatientAdmissionSchedule patientAdmissionSchedule) {
  JButton footprint = SwingUtils.makeSmallButton(new JButton("Patient9999"));
  int footprintWidth = footprint.getPreferredSize().width;
  timeTablePanel.defineColumnHeaderByKey(HEADER_COLUMN_GROUP2); // Department Header
  timeTablePanel.defineColumnHeaderByKey(HEADER_COLUMN_GROUP1); // Room Header
  timeTablePanel.defineColumnHeaderByKey(HEADER_COLUMN); // Bed Header
  for (Night night : patientAdmissionSchedule.getNightList()) {
    timeTablePanel.defineColumnHeader(night, footprintWidth);
  }
  timeTablePanel.defineRowHeaderByKey(HEADER_ROW); // Night header
  timeTablePanel.defineRowHeader(null); // Unassigned bed
  for (Bed bed : patientAdmissionSchedule.getBedList()) {
    timeTablePanel.defineRowHeader(bed);
  }
}

代码示例来源:origin: kiegroup/optaplanner

private void defineGrid(TennisSolution tennisSolution) {
  JButton footprint = SwingUtils.makeSmallButton(new JButton("999999"));
  int footprintWidth = footprint.getPreferredSize().width;
  datesPanel.defineColumnHeaderByKey(HEADER_COLUMN);
  for (Day day : tennisSolution.getDayList()) {
    datesPanel.defineColumnHeader(day, footprintWidth);
  }
  datesPanel.defineColumnHeaderByKey(TRAILING_HEADER_COLUMN); // Assignment count
  datesPanel.defineRowHeaderByKey(HEADER_ROW);
  for (Team team : tennisSolution.getTeamList()) {
    datesPanel.defineRowHeader(team);
  }
  datesPanel.defineRowHeader(null); // Unassigned
  confrontationsPanel.defineColumnHeaderByKey(HEADER_COLUMN);
  for (Team team : tennisSolution.getTeamList()) {
    confrontationsPanel.defineColumnHeader(team);
  }
  confrontationsPanel.defineRowHeaderByKey(HEADER_ROW);
  for (Team team : tennisSolution.getTeamList()) {
    confrontationsPanel.defineRowHeader(team);
  }
}

代码示例来源:origin: kiegroup/optaplanner

private void defineGrid(CourseSchedule courseSchedule) {
  JButton footprint = SwingUtils.makeSmallButton(new JButton("LinLetGre1-0"));
  int footprintWidth = footprint.getPreferredSize().width;

代码示例来源:origin: kiegroup/optaplanner

private void defineGrid(InvestmentSolution solution) {
  JButton footprint = SwingUtils.makeSmallButton(new JButton("99999999"));
  int footprintWidth = footprint.getPreferredSize().width;

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

@Override
public Dimension getPreferredSize() {
  Component[] comps = getAllComponents();
  Insets insets = getInsets();
  int width = null == insets ? 0 : insets.left + insets.right;
  int height = null == insets ? 0 : insets.top + insets.bottom;
  for (int i = 0; i < comps.length; i++) {
    Component comp = comps[i];
  if (!comp.isVisible()) {
  continue;
  }
    width += getOrientation() == HORIZONTAL ? comp.getPreferredSize().width : comp.getPreferredSize().height;
    height = Math.max( height, getOrientation() == HORIZONTAL ? comp.getPreferredSize().height : comp.getPreferredSize().width );
  }
  if(overflowToolbar.getComponentCount() > 0) {
    width += getOrientation() == HORIZONTAL ? overflowButton.getPreferredSize().width : overflowButton.getPreferredSize().height;
  }
  Dimension dim = getOrientation() == HORIZONTAL ? new Dimension(width, height) : new Dimension(height, width);
  return dim;        
}

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

needButtonSizeW = Math.max(needButtonSizeW, button.getPreferredSize().width);

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

if (button.getPreferredSize().width > maxWidth) maxWidth = button.getPreferredSize().width;
if (button.getPreferredSize().height > maxHeight) maxHeight = button.getPreferredSize().height;

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

int sizeSoFar = 0;
int maxSize = getOrientation() == HORIZONTAL ? getWidth() : getHeight();
int overflowButtonSize = getOrientation() == HORIZONTAL ? overflowButton.getPreferredSize().width : overflowButton.getPreferredSize().height;
int showingButtons = 0; // all that return true from isVisible()
int visibleButtons = 0; // all visible that fit into the given space (maxSize)

代码示例来源:origin: freeplane/freeplane

private int getPreferredWidth(JButton[] buttons) {
  double maxButtonWidth = 0;
  for (JButton button : buttons) {
    final Dimension size = button.getPreferredSize();
    if (size.getWidth() > maxButtonWidth)
      maxButtonWidth = size.getWidth();
  }
  // activate/deactivate exclude each other -> -1
  int spacer = ButtonsInCellRenderer.BUTTON_SPACER;
  return (int) ((buttons.length - 1) * (maxButtonWidth + spacer)) + spacer;
}

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

JButton button = new JButton("+");
Dimension size = button.getPreferredSize();
size.x += 6;
size.y += 6;
button.setPreferredSize(size);
Rectangle rectangle = new Rectangle(3, 3, size.x - 3, size.y - 3);
ScreenImage buttonImage = ScreenImage(button, rectangle);
ImageIcon icon = new ImageIcon(buttonImage);

JButton plus = new JButton(icon);
plus.setBorder( ... );

代码示例来源:origin: protegeproject/protege

public Dimension preferredLayoutSize(Container parent) {
  Insets insets = parent.getInsets();
  Dimension dim = tabbedPane.getPreferredSize();
  int totalWidth = insets.left + insets.right + 2 * dim.width + button.getPreferredSize().width;
  int totalHeight = insets.top + insets.bottom + dim.height;
  return new Dimension(totalWidth, totalHeight);
}

相关文章

JButton类方法