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

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

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

JButton.setPreferredSize介绍

暂无

代码示例

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

private void uiLayout () {
  title.setLayout(new GridLayout(1, 2));
  
  minimize.setPreferredSize(new Dimension(50, 26));
  exit.setPreferredSize(new Dimension(50, 26));
  title.add(minimize);
  title.add(exit);
  topBar.setLayout(new GridLayout(1, 1));
  topBar.add(windowLabel, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTHWEST, VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
  setLayout(new GridBagLayout());
  add(topBar, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTH, HORIZONTAL, new Insets(0, 0, 0, 100), 0, 10));
  add(title, new GridBagConstraints(0, 0, 0, 0, 0, 0, NORTHEAST, NONE, new Insets(0, 0, 0, 0), 0, 0));
  add(logo, new GridBagConstraints(0, 0, 1, 1, 1, 0, CENTER, HORIZONTAL, new Insets(40, 6, 6, 6), 0, 0));
  add(form, new GridBagConstraints(0, 1, 1, 1, 1, 0, CENTER, HORIZONTAL, new Insets(6, 6, 0, 6), 0, 0));
  add(buttonPanel, new GridBagConstraints(0, 2, 1, 1, 0, 0, CENTER, NONE, new Insets(0, 0, 0, 0), 0, 0));
  add(scrollPane, new GridBagConstraints(0, 3, 1, 1, 1, 1, CENTER, BOTH, new Insets(6, 6, 6, 6), 0, 0));
}

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

JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(4,4,4,4));

for(int i=0 ; i<16 ; i++){
  JButton btn = new JButton(String.valueOf(i));
  btn.setPreferredSize(new Dimension(40, 40));
  panel.add(btn);
}
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);

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

if (solutionBusiness.hasImporter()) {
  importAction = new ImportAction();
  importButton = new JButton(importAction);
} else {
  importButton = null;
JButton openButton = new JButton(openAction);
saveAction = new SaveAction();
saveAction.setEnabled(false);
JButton saveButton = new JButton(saveAction);
JButton exportButton;
if (solutionBusiness.hasExporter()) {
solvePanel.add(terminateSolvingEarlyButton, "terminateSolvingEarlyAction");
solveButton.setMinimumSize(terminateSolvingEarlyButton.getMinimumSize());
solveButton.setPreferredSize(terminateSolvingEarlyButton.getPreferredSize());

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

/**
 * Creates an empty JButton to be used as the scroll bar's arrows (to disable the arrows).
 */
protected JButton createEmptyButton()
{
  JButton button = new JButton();
  Dimension zeroDim = new Dimension(0, 0);
  button.setPreferredSize(zeroDim);
  button.setMinimumSize(zeroDim);
  button.setMaximumSize(zeroDim);
  return button;
}

代码示例来源:origin: 4thline/cling

@PostConstruct
public void init() {
  setLayout(new BorderLayout());
  refreshDevicesButton.setPreferredSize(new Dimension(2500, 32));
  refreshDevicesButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent actionEvent) {
      presenter.onRefreshDevices();
    }
  });
  browserToolBar.setFloatable(false);
  browserToolBar.add(refreshDevicesButton);
  // Disables auto-resizing, will fit Container view
  deviceListPane.setPreferredSize(new Dimension(100, 100));
  add(browserToolBar, BorderLayout.SOUTH);
  add(deviceListPane, BorderLayout.CENTER);
}

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

private JButton createButton() {
  JButton button = new JButton();
  button.setModel(buttonModel);
  button.setUI(new GaugeButtonUI());
  button.setOpaque(false);
  button.setPreferredSize(BUTTON_SIZE);
  button.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      buttonModel.turnNextLightOn();
      turnAllLightsOffIfAllAreOn();
    }
  });
  return button;
}

代码示例来源:origin: skylot/jadx

public ProgressPanel(final MainWindow mainWindow, boolean showCancelButton) {
  progressLabel = new JLabel();
  progressBar = new JProgressBar(0, 100);
  progressBar.setIndeterminate(true);
  progressBar.setStringPainted(false);
  progressLabel.setLabelFor(progressBar);
  setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
  setVisible(false);
  add(progressLabel);
  add(progressBar);
  if (showCancelButton) {
    JButton cancelButton = new JButton(ICON_CANCEL);
    cancelButton.setPreferredSize(new Dimension(ICON_CANCEL.getIconWidth(), ICON_CANCEL.getIconHeight()));
    cancelButton.setToolTipText("Cancel background jobs");
    cancelButton.setBorderPainted(false);
    cancelButton.setFocusPainted(false);
    cancelButton.setContentAreaFilled(false);
    cancelButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        mainWindow.cancelBackgroundJobs();
      }
    });
    add(cancelButton);
  }
}

代码示例来源:origin: 4thline/cling

setMinimumSize(new Dimension(300,150));
setResizable(true);
invokeActionButton.setPreferredSize(new Dimension(5000, 25));
invocationToolBar.add(invokeActionButton);
cancelActionButton.setPreferredSize(new Dimension(5000, 25));
invocationToolBar.add(cancelActionButton);

代码示例来源: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: stackoverflow.com

firstPanel.setMaximumSize(new Dimension(400, 400));
JButton btn;
for (int i=1; i<=4; i++) {
  for (int j=1; j<=4; j++) {
    btn = new JButton();
    btn.setPreferredSize(new Dimension(100, 100));
    firstPanel.add(btn);
secondPanel.setMaximumSize(new Dimension(520, 200));
for (int i=1; i<=5; i++) {
  for (int j=1; j<=13; j++) {
    btn = new JButton();
    btn.setPreferredSize(new Dimension(40, 40));
    secondPanel.add(btn);

代码示例来源:origin: 4thline/cling

useButton.setPreferredSize(new Dimension(500, 25));
useButton.setFocusable(false);
toolbar.add(useButton);
monitorButton.setPreferredSize(new Dimension(500, 25));
monitorButton.setFocusable(false);
toolbar.add(monitorButton);
invokeButton.setPreferredSize(new Dimension(500, 25));
invokeButton.setFocusable(false);
toolbar.add(invokeButton);
queryButton.setPreferredSize(new Dimension(500, 25));
queryButton.setFocusable(false);
toolbar.add(queryButton);
copyButton.setPreferredSize(new Dimension(500, 25));
copyButton.setFocusable(false);
toolbar.add(copyButton);
closeButton.setPreferredSize(new Dimension(500, 25));
closeButton.setFocusable(false);
toolbar.add(closeButton);

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

private JButton createButton(String text) {
  JButton button = new JButton(text);
  button.setPreferredSize(new Dimension(0, button.getPreferredSize().height));
  return button;
}

代码示例来源:origin: bonnyfone/vectalign

JPanel panelTo = new JPanel(new BorderLayout());
svgFrom = new SVGDrawingPanel();
svgFrom.setPreferredSize(new Dimension(190, 200));
svgTo = new SVGDrawingPanel();
svgTo.setPreferredSize(new Dimension(190, 200));
btnEditFrom = new JButton("Edit Path");
btnEditTo = new JButton("Edit Path");
btnSvgFrom = new JButton("Load SVG");
btnSvgTo = new JButton("Load SVG");
panelControls.setPreferredSize(new Dimension(400, 200));
panelControls.setBorder(getCommonBorder("Configure morphing", true));
panelControls.setLayout(new GridLayout(1, 2));
sliderMorphing.setPreferredSize(new Dimension(350, 25));
btnMorphAnimation = new JButton(icnPlay);
btnMorphAnimation.setPreferredSize(new Dimension(35, 35));
btnMorphAnimation.setBorderPainted(false);
btnMorphAnimation.setBorder(null);

代码示例来源:origin: 4thline/cling

startButton.setPreferredSize(new Dimension(5000, 25));
stopButton.setPreferredSize(new Dimension(5000, 25));
setMinimumSize(new Dimension(300, 150));
setPreferredSize(new Dimension(450, 150));
pack();

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

JButton btn = new JButton();
btn.add(new JLabel(text));
btn.add(new JLabel(img));
btn.setLayout(/*best layout choice here*/);
btn.setPreferredSize(new Dimension(x,y));
btn.setMaximumSize(new Dimension(maxX, minY));
btn.setMinimumSize(new Dimension(minX, minY)); //this one is most important when it comes to layoutmanagers

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

public void start() throws Exception {
  mainFrame=new JFrame("Chat demo");
  mainFrame.setPreferredSize(new Dimension(600,600));
  mainFrame.setBackground(Color.white);
  mainFrame.addWindowListener(new WindowAdapter() {
  txtArea.setPreferredSize(new Dimension(550, 500));
  txtArea.setEditable(false);
  txtArea.setBackground(Color.white);
  main_box.add(buttons);
  csLabel.setPreferredSize(new Dimension(85, 30));
  input.add(csLabel);
  leaveButton=new JButton("Leave");
  leaveButton.setPreferredSize(new Dimension(150, 30));
  buttons.add(leaveButton);
  leaveButton.addMouseListener(new MouseAdapter() {
  sendButton=new JButton("Send");
  sendButton.setPreferredSize(new Dimension(150, 30));
  buttons.add(sendButton);
  sendButton.addMouseListener(new MouseAdapter() {
  clearButton=new JButton("Clear");
  clearButton.setPreferredSize(new Dimension(150, 30));
  clearButton.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {

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

private void setGUISize() {
  Font font = GUISizeHelper.gameRequestsFont;
  lblText.setFont(font);
  lblText.setMaximumSize(new Dimension(300 + font.getSize() * 15, 20 + font.getSize() * 5));
  lblText.setMinimumSize(new Dimension(300 + font.getSize() * 15, 20 + font.getSize() * 5));
  lblText.setPreferredSize(new Dimension(300 + font.getSize() * 15, 20 + font.getSize() * 5));
  btn1.setFont(font);
  btn1.setMinimumSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn1.setMaximumSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn1.setPreferredSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn2.setFont(font);
  btn2.setMinimumSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn2.setMaximumSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn2.setPreferredSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn3.setFont(font);
  btn3.setMinimumSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn3.setMaximumSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  btn3.setPreferredSize(new Dimension(50 + 4 * font.getSize(), 2 * font.getSize() + 10));
  JComponent c = ((BasicInternalFrameUI) this.getUI()).getNorthPane();
  c.setMinimumSize(new Dimension(c.getMinimumSize().width, font.getSize() + 10));
  c.setMaximumSize(new Dimension(c.getMaximumSize().width, font.getSize() + 10));
  c.setPreferredSize(new Dimension(c.getPreferredSize().width, font.getSize() + 10));
  c.setFont(font);
}

代码示例来源:origin: net.sf.squirrel-sql.plugins/hibernate

public void addToToolbar(AbstractAction action)
{
 JButton btn = new JButton(action);
 Dimension size = btn.getPreferredSize();
 size.height = _panel.btnConnected.getPreferredSize().height;
 btn.setPreferredSize(size);
 
 _panel.addToToolbar(btn);
}

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

JButton button = new JButton(new QueenAction(queen));
button.setMinimumSize(new Dimension(20, 20));
button.setPreferredSize(new Dimension(20, 20));
button.setToolTipText(toolTip);
add(button);

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

int w = getOrientation() == HORIZONTAL ? overflowButton.getIcon().getIconWidth() + 4 : getWidth() - getInsets().left - getInsets().right;
int h = getOrientation() == HORIZONTAL ? getHeight() - getInsets().top - getInsets().bottom : overflowButton.getIcon().getIconHeight() + 4;
overflowButton.setMaximumSize(new Dimension(w, h));
overflowButton.setMinimumSize(new Dimension(w, h));
overflowButton.setPreferredSize(new Dimension(w, h));

相关文章

JButton类方法