java.awt.Toolkit.getScreenSize()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(212)

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

Toolkit.getScreenSize介绍

[英]Gets the size of the screen. On systems with multiple displays, the primary display is used. Multi-screen aware display dimensions are available from GraphicsConfiguration and GraphicsDevice.
[中]获取屏幕的大小。在具有多个显示器的系统上,使用主显示器。支持多屏幕的显示尺寸可从GraphicsConfigurationGraphicsDevice获得。

代码示例

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

/**
 * @return the screen height from Toolkit.getScreenSize()
 * if possible, otherwise returns 600
 * @see java.awt.Toolkit
 */
protected static int getScreenHeight() {
 try {
  return Toolkit.getDefaultToolkit().getScreenSize().height;
 } catch (Throwable t) {
  return 600;
 }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private static void createWindowForPanel(AwtPanel panel, int location){
  JFrame frame = new JFrame("Render Display " + location);
  frame.getContentPane().setLayout(new BorderLayout());
  frame.getContentPane().add(panel, BorderLayout.CENTER);
  frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  frame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosed(WindowEvent e) {
      if (++panelsClosed == 2){
        app.stop();
      }
    }
  });
  frame.pack();
  frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
  frame.setVisible(true);
}

代码示例来源:origin: deathmarine/Luyten

JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int) (screenSize.width * 0.35);
if (width < MIN_WIDTH) {
  width = MIN_WIDTH;
final Dimension center = new Dimension(width, 500);
final int x = (int) (center.width * 0.2);
final int y = (int) (center.height * 0.2);

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

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets scnMax = Toolkit.getDefaultToolkit().
    getScreenInsets(dialog.getGraphicsConfiguration());
int taskBarSize = scnMax.bottom;
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);

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

private static void doShowCentred(Window parent, Window dialog) {
  if (parent == null) {
    doCentre(dialog, Toolkit.getDefaultToolkit().getScreenSize());
  } else {
    doCentre(dialog, parent.getSize());
  }
  dialog.setVisible(true);
}

代码示例来源:origin: org.boofcv/boofcv-swing

public static JFrame showWindow( final JComponent component , String title, final boolean closeOnExit ) {
  final JFrame frame = new JFrame(title);
  frame.add(component, BorderLayout.CENTER);
  SwingUtilities.invokeLater(() -> {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    frame.pack();
    frame.setLocationRelativeTo(null); // centers window in the monitor
    // prevent it from creating a window larger than the screen
    int width = frame.getWidth();
    int height = frame.getHeight();
    if( width > screenSize.width || height > screenSize.height ) {
      width = Math.min(width,screenSize.width);
      height = Math.min(height,screenSize.height);
      frame.setSize(width,height);
    }
    frame.setVisible(true);
    if( closeOnExit )
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  });
  return frame;
}

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

public static void main(String[] args) {
  JFrame frame = new JFrame();

  Dimension min = new Dimension(500,500);
  frame.setMinimumSize(min);

  Toolkit toolkit = Toolkit.getDefaultToolkit();
  Dimension max = toolkit.getScreenSize();
  frame.setMaximumSize(max);

  frame.setVisible(true);
  frame.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

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

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

class TestFrameSize {

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        JFrame f = new JFrame("Test Screen Size");
        f.setAlwaysOnTop(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        System.out.println(f.getToolkit().getScreenSize());
        f.setExtendedState(Frame.MAXIMIZED_BOTH);
        f.setVisible(true);
        System.out.println(f.getSize());
      }
    });
  }
}

代码示例来源:origin: Talend/tesb-rt-se

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.
 */
private static void createAndShowGUI(CarSearchModel searchModel, CarReserveModel reserveModel) {
  //Create and set up the window.
  JFrame appFrame = new JFrame(Messages.CarRentalClient_Title);
  appFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  // Display the window centered on the screen
  Dimension d = appFrame.getToolkit().getScreenSize();
  appFrame.setLocation((d.width / 2) - (appFrame.getWidth() / 2), (appFrame.getHeight() / 2));
  CarRentalClientGui gui = new CarRentalClientGui(searchModel, reserveModel);
  gui.appFrame = appFrame;
  appFrame.setContentPane(gui);        
  appFrame.pack();
  appFrame.setVisible(true);
  appFrame.toFront();
}

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

private void createRuleXML() {
  CreateXMLRulePanel rulePanel = new CreateXMLRulePanel(xpathQueryArea, codeEditorPane);
  JFrame xmlframe = new JFrame("Create XML Rule");
  xmlframe.setContentPane(rulePanel);
  xmlframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  xmlframe.setSize(new Dimension(600, 700));
  xmlframe.addComponentListener(new java.awt.event.ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      JFrame tmp = (JFrame) e.getSource();
      if (tmp.getWidth() < 600 || tmp.getHeight() < 700) {
        tmp.setSize(600, 700);
      }
    }
  });
  int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
  int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
  xmlframe.pack();
  xmlframe.setLocation((screenWidth - xmlframe.getWidth()) / 2, (screenHeight - xmlframe.getHeight()) / 2);
  xmlframe.setVisible(true);
}

代码示例来源:origin: deathmarine/Luyten

wrap.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Dimension center = new Dimension((int) (screenSize.width * 0.35),
    Math.min((int) (screenSize.height * 0.20), 200));
final int x = (int) (center.width * 0.2);

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

final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(
  getGraphicsConfiguration());
final int taskBarSize = scnMax.bottom;
  l.setOpaque(false);
  c.add(l, constraints);
  b.setFocusable(false);
  c.add(b, constraints);

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

/**
 * @return the screen width from Toolkit.getScreenSize()
 * if possible, otherwise returns 800
 * @see java.awt.Toolkit
 */
protected static int getScreenWidth() {
 try {
  return Toolkit.getDefaultToolkit().getScreenSize().width;
 } catch (Throwable t) {
  return 800;
 }
}

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

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

public class FrameInfo
{
  public static void main(String[] args)
  {
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = env.getMaximumWindowBounds();
    System.out.println("Screen Bounds: " + bounds );

    GraphicsDevice screen = env.getDefaultScreenDevice();
    GraphicsConfiguration config = screen.getDefaultConfiguration();
    System.out.println("Screen Size  : " + config.getBounds());
    System.out.println(Toolkit.getDefaultToolkit().getScreenSize());

    JFrame frame = new JFrame("Frame Info");
    frame.setSize(200, 200);
    frame.setVisible( true );

    System.out.println("Frame Size   : " + frame.getSize() );
    System.out.println("Frame Insets : " + frame.getInsets() );
    System.out.println("Content Size : " + frame.getContentPane().getSize() );
   }
}

代码示例来源:origin: jpos/jPOS

private JFrame initFrame (Element ui) {
  Element caption = ui.getChild ("caption");
  mainFrame = caption == null ?  
    new JFrame () :
    new JFrame (caption.getText());
  JOptionPane.setRootFrame (mainFrame);
  mainFrame.getContentPane().setLayout(new BorderLayout());
  String close = ui.getAttributeValue ("close");
  if ("false".equals (close))
    mainFrame.setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE);
  else if ("exit".equals (close))
    mainFrame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  mainFrame.setSize(getDimension (ui, screenSize));
  locateOnScreen(mainFrame);
  return mainFrame;
}

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

frame.getContentPane().add(containerSplitPane);
frame.setDefaultCloseOperation(exitOnClose ? JFrame.EXIT_ON_CLOSE : WindowConstants.DISPOSE_ON_CLOSE);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;

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

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int begX = (int) (screenSize.width * 0.05);
int begY = (int) (screenSize.height * 0.05);
if (screenSize.height > 800) { screenSize.height = 800; }
setPreferredSize(screenSize);
Dimension displayMatchesSize = new Dimension((int) (screenSize.getWidth()),(int) (screenSize.getHeight()*3/4.));
displayMatchesPanel.setPreferredSize(displayMatchesSize);

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

if (useSlideButton) {
  final JPanel statusPanel = new JPanel();
  basePanel.add(statusPanel, BorderLayout.SOUTH);
  statusPanel.add(new JButton("Slide Left") {
    private static final long serialVersionUID = 9204819004142223529L;
  statusPanel.add(new JButton("Slide Right") {
  Toolkit.getDefaultToolkit().beep();
  int step = 0;
  if ((slideType == LEFT) || (slideType == RIGHT)) {
    step = (int) (((float) parent.getWidth() / (float) Toolkit.getDefaultToolkit().getScreenSize().width) * 40.f);
    step = (int) (((float) parent.getHeight() / (float) Toolkit.getDefaultToolkit().getScreenSize().height) * 20.f);

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

/**
 * @return the screen height from Toolkit.getScreenSize()
 * if possible, otherwise returns 600
 * @see java.awt.Toolkit
 */
protected static int getScreenHeight() {
 try {
  return Toolkit.getDefaultToolkit().getScreenSize().height;
 } catch (Throwable t) {
  return 600;
 }
}

相关文章