javax.swing.JFrame.setLocationRelativeTo()方法的使用及代码示例

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

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

JFrame.setLocationRelativeTo介绍

暂无

代码示例

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

public void run () {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(480, 320);
    frame.setLocationRelativeTo(null);
    JPanel panel = new JPanel();
    frame.getContentPane().add(panel);
    panel.add(new NewSlider(200, 100, 500, 0.1f, 150, 300));
    frame.setVisible(true);
  }
});

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

public void run(){
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    createFrame();
    currentPanel.add(canvas, BorderLayout.CENTER);
    frame.pack();
    startApp();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
});

代码示例来源:origin: wiztools/rest-client

@PostConstruct
public void show() {
  initJFC();
  
  frame.setContentPane(view.getContainer());
  createMenu();
  ImageIcon icon =
      UIUtil.getIconFromClasspath("org/wiztools/restclient/logo_30.png");
  frame.setIconImage(icon.getImage());
  frame.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent event){
      shutdownCall();
    }
  });
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
  
  // Update check:
  new Thread(ServiceLocator.getInstance(AppUpdateRunner.class)).start();
}

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

JFrame frame = new JFrame ();
frame.setSize ( 500, 300 );
frame.setLocationRelativeTo ( null );
frame.setVisible ( true );

代码示例来源:origin: Nilhcem/FakeSMTP

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.addWindowListener(new WindowAdapter() {
  @Override
mainFrame.setLocationRelativeTo(null); // Center main frame
mainFrame.setIconImage(iconImage);
mainFrame.setVisible(true);

代码示例来源:origin: fossasia/neurolab-desktop

window.setLocationRelativeTo(null);
window.setVisible(true);

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

public void run () {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(480, 320);
    frame.setLocationRelativeTo(null);
    JPanel panel = new JPanel();
    frame.getContentPane().add(panel);
    panel.add(new NewSlider(200, 100, 500, 0.1f, 150, 300));
    frame.setVisible(true);
  }
});

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

public void run () {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(480, 320);
    frame.setLocationRelativeTo(null);
    JPanel panel = new JPanel();
    frame.getContentPane().add(panel);
    panel.add(new Slider(200, 100, 500, 0.1f, 150, 300));
    frame.setVisible(true);
  }
});

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

public void run () {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.setSize(480, 320);
    frame.setLocationRelativeTo(null);
    JPanel panel = new JPanel();
    frame.getContentPane().add(panel);
    panel.add(new Slider(200, 100, 500, 0.1f, 150, 300));
    frame.setVisible(true);
  }
});

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

JFrame frame = new JFrame("FooRendererTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel); // or whatever...
frame.pack();
frame.setLocationRelativeTo(null);  // *** this will center your app ***
frame.setVisible(true);

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

public static void main(String[] args) throws MalformedURLException {
   URL url = new URL("<URL to your Animated GIF>");
   Icon icon = new ImageIcon(url);
   JLabel label = new JLabel(icon);
   JFrame f = new JFrame("Animation");
   f.getContentPane().add(label);
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.pack();
   f.setLocationRelativeTo(null);
   f.setVisible(true);
 }

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

JFrame jFrame = new JFrame("Test");
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//jFrame.setLocationRelativeTo(null);
jFrame.setSize(600, 600);
jFrame.pack();
jFrame.setVisible(true);
jFrame.setLocationRelativeTo(null); //To center the code

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

private static void createAndShowGUI() {
  // Create and set up the window.
  JFrame frame = new JFrame("SpotBugs browser integration Test");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  // Add content to the window.
  frame.add(new TestDesktopIntegration());
  // Display the window.
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}

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

public static void main(String[] args) {
  JFrame frame = new JFrame();
  frame.setLayout(new GridBagLayout());
  JPanel panel = new JPanel();
  panel.add(new JLabel("This is a label"));
  panel.setBorder(new LineBorder(Color.BLACK)); // make it easy to see
  frame.add(panel, new GridBagConstraints());
  frame.setSize(400, 400);
  frame.setLocationRelativeTo(null);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);
}

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

public static void main ( String[] args )
{
  JPanel middlePanel = new JPanel ();
  middlePanel.setBorder ( new TitledBorder ( new EtchedBorder (), "Display Area" ) );

  // create the middle panel components

  JTextArea display = new JTextArea ( 16, 58 );
  display.setEditable ( false ); // set textArea non-editable
  JScrollPane scroll = new JScrollPane ( display );
  scroll.setVerticalScrollBarPolicy ( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );

  //Add Textarea in to middle panel
  middlePanel.add ( scroll );

  // My code
  JFrame frame = new JFrame ();
  frame.add ( middlePanel );
  frame.pack ();
  frame.setLocationRelativeTo ( null );
  frame.setVisible ( true );
}

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

public void run(){
    JFrame frame = new JFrame("Render Display");
    display = new ImageDisplay();
    display.setPreferredSize(new Dimension(width, height));
    frame.getContentPane().add(display);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter(){
      public void windowClosed(WindowEvent e){
        stop();
      }
    });
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setResizable(false);
    frame.setVisible(true);
  }
});

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

JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(label);
frame.setSize(100, 100);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

private void showHistory() {
 if (historyFrame == null) {
  historyFrame = new JFrame("Statistics History");
 } else {
  historyFrame.setVisible(false);
  historyFrame= new JFrame("Statistics History");
 }
 historyFrame.setLayout(new GridLayout(1,0));
 Object[][] entries = new Object[historyList.size()][3];
 for(int i = 0; i < historyList.size(); i++) {
  entries[i] = historyList.get(i).toArray();
 }
 DefaultTableModel tableModel = new TregexGUITableModel(entries, HistoryEntry.columnNamesArray());
 JTable statTable = new JTable(tableModel);
 DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) statTable.getDefaultRenderer(String.class);
 dtcr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
 JScrollPane scroller = new JScrollPane(statTable);
 historyFrame.add(scroller);
 historyFrame.pack();
 historyFrame.setLocationRelativeTo(TregexGUI.getInstance());
 historyFrame.setBackground(Color.WHITE);
 historyFrame.setVisible(true);
 historyFrame.repaint();
}

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

return;
final JFrame exceptionFrame = new JFrame("Uncaught exception: " + e.getMessage());
Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
BufferedImage errorImage = new BufferedImage(
errorIcon.paintIcon(null, errorImage.getGraphics(), 0, 0);
exceptionFrame.setIconImage(errorImage);
exceptionFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JPanel contentPanel = new JPanel(new BorderLayout(5, 5));
contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
exceptionFrame.pack();
exceptionFrame.setLocationRelativeTo(null);
exceptionFrame.setVisible(true);

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

JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
  @Override
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

相关文章

JFrame类方法