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

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

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

JDialog.getPreferredSize介绍

暂无

代码示例

代码示例来源:origin: chewiebug/GCViewer

public Dimension getPreferredSize() {
  Dimension size = super.getPreferredSize();
  
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(getOwner().getGraphicsConfiguration());
  int taskBarSize = scnMax.bottom;
  
  int usableScreenHeight = screenSize.height - taskBarSize - 50;
  
  if (size.height > (usableScreenHeight)) {
    size.height = usableScreenHeight;
  }
  
  return size;
}

代码示例来源:origin: stanfordnlp/CoreNLP

dialog.add(cancel);
dialog.pack();
dialog.setSize(dialog.getPreferredSize());
dialog.setVisible(true);

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

public Dimension getPreferredSize() {
  return new Dimension(300, super.getPreferredSize().height);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

public Dimension getPreferredSize () {
  return new Dimension (300, super.getPreferredSize ().height);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

public Dimension getPreferredSize () {
  return new Dimension (300, super.getPreferredSize ().height);
}

代码示例来源:origin: org.apache.uima/uimaj-tools

@Override
public Dimension getPreferredSize() {
 Dimension screenSize = getToolkit().getScreenSize();
 Dimension d = super.getPreferredSize();
 return new Dimension(screenSize.width, d.height);
 // return getToolkit().getScreenSize();
}

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

public static void adjustWidthForTitle(JDialog dialog)
{
  // make sure that the dialog is not smaller than its title
  // this is not an ideal method, but I can't figure out a better one
  Font defaultFont = UIManager.getDefaults().getFont("Label.font");
  int titleStringWidth = SwingUtilities.computeStringWidth(new JLabel().getFontMetrics(defaultFont),
      dialog.getTitle());

  // account for titlebar button widths. (estimated)
  titleStringWidth += 110;

  // set minimum width
  Dimension currentPreferred = dialog.getPreferredSize();

  // +10 accounts for the three dots that are appended when the title is too long
  if(currentPreferred.getWidth() + 10 <= titleStringWidth)
  {
    dialog.setPreferredSize(new Dimension(titleStringWidth, (int) currentPreferred.getHeight()));

  }
}

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

if (visible) {
  dlg.pack();
  Dimension prefSize = dlg.getPreferredSize();
  Toolkit toolkit = Toolkit.getDefaultToolkit();
  Dimension screenSize = toolkit.getScreenSize();

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

window.getContentPane().add(holderPanel, BorderLayout.NORTH);
window.pack();
Dimension windowSize = window.getPreferredSize();
window.setSize(400, windowSize.height);
window.setResizable(false);

代码示例来源:origin: edu.stanford.protege/protege-editor-owl

window.getContentPane().add(holderPanel, BorderLayout.NORTH);
window.pack();
Dimension windowSize = window.getPreferredSize();
window.setSize(400, windowSize.height);
window.setResizable(false);

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

public void show(){
  dialog.setPreferredSize(this.preferredSize);
  dialog.pack();
  // center
  if(parentFrame != null){
    int newX = parentFrame.getX() + parentFrame.getWidth()/2 - dialog.getPreferredSize().width/2;
    int newY = parentFrame.getY() + parentFrame.getHeight()/2 - dialog.getPreferredSize().height/2;
    dialog.setLocation(newX, newY);
  }
  dialog.setVisible(true);
}

代码示例来源:origin: bcdev/beam

@Override
public void show() {
  if (dialog == null) {
    kernelForm = new FilterKernelForm(filter);
    propertiesForm = new FilterPropertiesForm(filter);
    dialog = new JDialog(parentWindow, "Filter", Dialog.ModalityType.MODELESS);
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Filter Kernel", kernelForm);
    tabbedPane.addTab("Filter Properties", propertiesForm);
    dialog.setContentPane(tabbedPane);
    dialog.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        preferences.putInt("x", e.getWindow().getX());
        preferences.putInt("y", e.getWindow().getY());
        preferences.putInt("width", e.getWindow().getWidth());
        preferences.putInt("height", e.getWindow().getHeight());
      }
    });
    Dimension preferredSize = dialog.getPreferredSize();
    int x = preferences.getInt("x", 100);
    int y = preferences.getInt("y", 100);
    int w = preferences.getInt("width", preferredSize.width);
    int h = preferences.getInt("height", preferredSize.height);
    dialog.setBounds(x, y, w, h);
  }
  dialog.setVisible(true);
}

代码示例来源:origin: senbox-org/s2tbx

private void insertMessageLabel() {
  Container parent = getDefaultIOParametersPanel().getParent();
  JScrollPane scrollPane = (JScrollPane) parent.getComponent(1);
  JViewport viewport = (JViewport) scrollPane.getComponent(0);
  JPanel initial = (JPanel) viewport.getComponent(0);
  Dimension preferredSize = initial.getPreferredSize();
  JPanel wrapper = new JPanel(new BorderLayout());
  wrapper.add(initial, BorderLayout.NORTH);
  wrapper.add(messagePanel, BorderLayout.SOUTH);
  messagePanel.setVisible(false);
  wrapper.setPreferredSize(preferredSize);
  viewport.remove(initial);
  viewport.add(wrapper);
  final Dimension windowSize = this.getJDialog().getPreferredSize();
  this.getJDialog().setMinimumSize(new Dimension(windowSize.width, windowSize.height + 30));
}

代码示例来源:origin: undera/jmeter-plugins

protected void repack() {
  JDialog dlgParent = getAssociatedDialog();
  if(dlgParent != null) {
    Dimension newSize = dlgParent.getPreferredSize();
    if(newSize.width < minWidth) {
      newSize.width = minWidth;
    }
    dlgParent.setSize(newSize);
    dlgParent.validate();
  }
}

代码示例来源:origin: undera/jmeter-plugins

public static JDialog getJDialogInstance(Frame owner, String title, boolean modal, JAbsrtactDialogPanel content, String imagePath) {
  if(!GraphicsEnvironment.isHeadless()) {
    JDialog ret = new JDialog(owner, title, modal);
    ret.add(content);
    ret.pack();
    Dimension size = ret.getPreferredSize();
    if(size.width < content.getMinWidth()) {
      size.width = content.getMinWidth();
    }
    ret.setSize(size);
    ret.validate();
    if(imagePath != null) {
      ImageIcon imageIcon = new ImageIcon(DialogFactory.class.getResource(imagePath));
      if(imageIcon != null) {
        ret.setIconImage(imageIcon.getImage());
      }
    }
    return ret;
  } else {
    return null;
  }
}

代码示例来源:origin: kg.apc/jmeter-plugins-cmn-jmeter

protected void repack() {
  JDialog dlgParent = getAssociatedDialog();
  if(dlgParent != null) {
    Dimension newSize = dlgParent.getPreferredSize();
    if(newSize.width < minWidth) {
      newSize.width = minWidth;
    }
    dlgParent.setSize(newSize);
    dlgParent.validate();
  }
}

代码示例来源:origin: kg.apc/jmeter-plugins-cmn-jmeter

public static JDialog getJDialogInstance(Frame owner, String title, boolean modal, JAbsrtactDialogPanel content, String imagePath) {
  if(!GraphicsEnvironment.isHeadless()) {
    JDialog ret = new JDialog(owner, title, modal);
    ret.add(content);
    ret.pack();
    Dimension size = ret.getPreferredSize();
    if(size.width < content.getMinWidth()) {
      size.width = content.getMinWidth();
    }
    ret.setSize(size);
    ret.validate();
    if(imagePath != null) {
      ImageIcon imageIcon = new ImageIcon(DialogFactory.class.getResource(imagePath));
      if(imageIcon != null) {
        ret.setIconImage(imageIcon.getImage());
      }
    }
    return ret;
  } else {
    return null;
  }
}

代码示例来源:origin: zitmen/thunderstorm

/**
 * shows the url in the static window, sizes and positions the window
 * accordingly
 */
private void showInTextWindow() throws IOException {
  window.setVisible(false);
  // same height as parent window of the button, positioned next to it on left or right side
  Window ancestor = SwingUtilities.getWindowAncestor(this);
  window.setPreferredSize(new Dimension(WINDOW_WIDTH, Math.max(ancestor.getHeight(), WINDOW_HEIGHT)));
  int screenEnd = ancestor.getGraphicsConfiguration().getBounds().width + ancestor.getGraphicsConfiguration().getBounds().x;
  Point ancestorLocation = ancestor.getLocationOnScreen();
  if(ancestorLocation.x + ancestor.getWidth() + window.getPreferredSize().width < screenEnd) {
    window.setLocation(ancestorLocation.x + ancestor.getWidth(), ancestorLocation.y);
  } else {
    window.setLocation(ancestorLocation.x - window.getPreferredSize().width, ancestorLocation.y);
  }
  //set page shown in browser
  if(url != null && !url.equals(htmlBrowser.getPage())) {
    try {
      htmlBrowser.setPage(url);
    } catch(Exception e) {
      htmlBrowser.setText("Could not load help file");
    }
  }
  window.pack();
  window.setVisible(true);
}

代码示例来源:origin: Baralga/baralga

dialog.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/Baralga-Tray.gif"))); //$NON-NLS-1$ 
Dimension d = dialog.getPreferredSize();
final Point preferredLeftTop = new Point(currentMousePosition.x - d.width / 2, currentMousePosition.y - d.height / 2);
AWTUtils.keepInScreenBounds(preferredLeftTop, dialog);

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

/**
 * Adjusts the size of the dialog to the preferred size, but only if that
 * is bigger than the current size.
 */
private void adjustSize() {
  if (dialog.isVisible()) {
    Dimension p = dialog.getPreferredSize();
    Point bottomRight = dialog.getLocationOnScreen();
    bottomRight.translate(p.width, p.height);
    if (bigger(p, dialog.getSize())
        && GuiUtil.isPointOnScreen(bottomRight)) {
      dialog.pack();
    }
  }
}

相关文章

JDialog类方法