java.awt.Window.setLocationRelativeTo()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(227)

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

Window.setLocationRelativeTo介绍

暂无

代码示例

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

package com.stackoverflow.test;

import java.net.URL;
import javax.swing.*;  // Wild carded for brevity. 
            // Actual code imports single classes
public class Main {
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable(){
      public void run() {
        URL url = Main.class.getResource(
                   "/resources/stackoverflow.png");
        ImageIcon icon = new ImageIcon(url);
        JFrame frame = new JFrame();
        frame.add(new JLabel(icon));
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    });
  }
}

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

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class OptionTest { 
  public static void main ( String [] args ) { 

    JFrame frame = new JFrame("My dialog asks....");

    frame.setUndecorated( true );
    frame.setVisible( true );
    frame.setLocationRelativeTo( null );

    String message = JOptionPane.showInputDialog(frame,
      "Would this be enough?.", 
      "My dialog asks....", 
      JOptionPane.INFORMATION_MESSAGE);

    System.out.println( "Got " + message );

    frame.dispose();
  }
}

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

this.add(combo1);
this.add(combo2);
combo1.addActionListener(this);
JFrame f = new JFrame("ComboTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

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

private JFrame frame = new JFrame("Test");
private JPanel panel = new JPanel();
private JLabel label = new JLabel("CenteredJLabel");
  panel.add(label);
  panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.add(panel);
  frame.setSize(400, 300);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);

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

for (int r = 0; r < N; r++) {
  for (int c = 0; c < N; c++) {
    this.add(create(r + N, r + 1, c + 2));
JFrame f = new JFrame("HTMLFractions");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

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

final JFrame frame = new JFrame("Nested Layout Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
plafComponents.add(plafChooser);
plafComponents.add(pack);
      SwingUtilities.updateComponentTreeUI(frame);
      if (pack.isSelected()) {
        frame.pack();
        frame.setMinimumSize(frame.getSize());
gui.add(plafComponents, BorderLayout.NORTH);
frame.pack();
frame.setLocationRelativeTo(null);
try {
frame.setVisible(true);

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

final JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(600, 400));
final JToolBar toolBar = new JToolBar();
toolBar.add(button);
frame.getContentPane().add(toolBar, BorderLayout.NORTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

Runnable r = new Runnable() {
 public void run() {
  final JFrame f = new JFrame("Test Screenshot");
  p.add( new JScrollPane(new JTree()),
   BorderLayout.WEST );
  p.add( new JScrollPane( new JTextArea(HELP,10,30) ),
   BorderLayout.CENTER );
  f.pack();
  f.setLocationRelativeTo(null);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setVisible(true);

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

JFrame f = new JFrame("GroupPanel");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
f.add(new GroupPanel(1));
f.add(new GroupPanel(2));
f.add(Box.createVerticalGlue());
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);

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

JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog"));
JPanel panel = new JPanel();
panel.add(showWaitBtn);
JFrame frame = new JFrame("Frame");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
progressBar.setIndeterminate(true);
JPanel panel = new JPanel(new BorderLayout());
panel.add(progressBar, BorderLayout.CENTER);
panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START);
dialog.add(panel);
dialog.pack();
dialog.setLocationRelativeTo(win);
dialog.setVisible(true);

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

JFrame frame = new JFrame();
frame.setTitle("Welcome!");
frame.setSize(520, 480);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel heroShotPanel = new JPanel();
JLabel heroShot = new JLabel(heroShotImage);
heroShotPanel.add(heroShot);
submitPanel.add(start);
frame.getContentPane().add(heroShotPanel, BorderLayout.NORTH);
frame.getContentPane().add(submitPanel, BorderLayout.SOUTH);
frame.setVisible(true);
frame.getRootPane().setDefaultButton(start);
start.requestFocus();

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

JFrame frame = new JFrame("DrawStuff");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new DrawStuff());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

JFrame f = new JFrame("MarqueeTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String s = "Tomorrow, and tomorrow, and tomorrow, "
+ "creeps in this petty pace from day to day, "
+ "sound and fury signifying nothing.";
MarqueePanel mp = new MarqueePanel(s, 32);
f.add(mp);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
mp.start();
label.setFont(new Font("Serif", Font.ITALIC, 36));
label.setText(sb.toString());
this.add(label);

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

mainPanel.setLayout(new BorderLayout());
draw = new DrawingArea();
mainPanel.add(draw, BorderLayout.CENTER);
mainPanel.add(userInt, BorderLayout.NORTH);
userInt.add(b1);
userInt.add(b2);
SwingUtilities.invokeLater(new Runnable() {
  public void run() {
   JFrame window = new JFrame("Ball");
   window.add(new StartingPoint().getMainPanel());
   window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   window.pack();
   window.setLocationRelativeTo(null);
   window.setVisible(true);

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

JFrame frame = new JFrame("TestAlphaComposite");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new TestAlphaComposite());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

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

menuBar.add(menu);
JFrame f = new JFrame("FileMenu");
f.setJMenuBar(menuBar);
f.add(toolBar, BorderLayout.CENTER);
f.add(label, BorderLayout.SOUTH);
f.pack();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);

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

JFrame frame = new JFrame();
JPanel panel = new JPanel();
JLabel label = new JLabel("Loading...");
int max = 1000;
jpb.setMaximum(max);
panel.add(label);
panel.add(jpb);
frame.add(panel);
frame.pack();
frame.setSize(200,90);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new Task_IntegerUpdate(jpb, max, label).execute();

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

JFrame frame = new JFrame("DrawGraph");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

JFrame frame = new JFrame();
JPanel panel = new JPanel();
JLabel label = new JLabel("Loading...");
JProgressBar jpb = new JProgressBar();
jpb.setIndeterminate(true);
panel.add(label);
panel.add(jpb);
frame.add(panel);
frame.pack();
frame.setSize(200,90);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new Task_StringUpdate(label).execute();

相关文章

Window类方法