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

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

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

JDialog.setLocationRelativeTo介绍

暂无

代码示例

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

final JDialog d = new JDialog();
d.setSize(200,200);
d.setLocationRelativeTo(null);
d.setVisible(true);

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

System.out.println("encoding null!!");
 setEncoding.setText(encoding);
 dialog.setVisible(false);
});
useOldEncoding.addActionListener(e -> dialog.setVisible(false));
useAnotherEncoding.addActionListener(e -> {
 dialog.setVisible(false);
 alternateEncodingPrompt(encoding);
});
dialog.getRootPane().setDefaultButton(useNewEncoding);
dialog.pack();
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);

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

protected JDialog createDialog(Component parent) {
  Frame frame = parent instanceof Frame ? (Frame) parent
      : (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parent);
  JDialog dialog = new JDialog(frame, ("Select Font"), true);
  Action okAction = new DialogOKAction(dialog);
  Action cancelAction = new DialogCancelAction(dialog);
  JButton okButton = new JButton(okAction);
  okButton.setFont(DEFAULT_FONT);
  JButton cancelButton = new JButton(cancelAction);
  cancelButton.setFont(DEFAULT_FONT);
  JPanel buttonsPanel = new JPanel();
  buttonsPanel.setLayout(new GridLayout(2, 1));
  buttonsPanel.add(okButton);
  buttonsPanel.add(cancelButton);
  buttonsPanel.setBorder(BorderFactory.createEmptyBorder(25, 0, 10, 10));
  ActionMap actionMap = buttonsPanel.getActionMap();
  actionMap.put(cancelAction.getValue(Action.DEFAULT), cancelAction);
  actionMap.put(okAction.getValue(Action.DEFAULT), okAction);
  InputMap inputMap = buttonsPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), cancelAction.getValue(Action.DEFAULT));
  inputMap.put(KeyStroke.getKeyStroke("ENTER"), okAction.getValue(Action.DEFAULT));
  JPanel dialogEastPanel = new JPanel();
  dialogEastPanel.setLayout(new BorderLayout());
  dialogEastPanel.add(buttonsPanel, BorderLayout.NORTH);
  dialog.getContentPane().add(this, BorderLayout.CENTER);
  dialog.getContentPane().add(dialogEastPanel, BorderLayout.EAST);
  dialog.pack();
  dialog.setLocationRelativeTo(frame);
  return dialog;
}

代码示例来源:origin: igniterealtime/Openfire

bar.setStringPainted(true);
dialog.getContentPane().add(bar, BorderLayout.CENTER);
dialog.pack();
dialog.setSize(225, 55);
dialog.setLocationRelativeTo(frame);
dialog.setVisible(true);

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

public void editMetadata() {
  if (getActiveNode() == null) return;
  JDialog editorDialog = new NodeAttributesDialog(NodeBoxDocument.this);
  editorDialog.setSize(580, 751);
  editorDialog.setLocationRelativeTo(NodeBoxDocument.this);
  editorDialog.setVisible(true);
}

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

public ConferenceCFPImportWorker(SolutionBusiness<ConferenceSolution> solutionBusiness,
    SolutionPanel<ConferenceSolution> solutionPanel, String conferenceBaseUrl) {
  this.solutionBusiness = solutionBusiness;
  this.solutionPanel = solutionPanel;
  this.conferenceBaseUrl = conferenceBaseUrl;
  dialog = new JDialog(solutionPanel.getSolverAndPersistenceFrame(), true);
  JPanel contentPane = new JPanel(new BorderLayout(10, 10));
  contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  contentPane.add(new JLabel("Importing CFP data in progress..."), BorderLayout.NORTH);
  JProgressBar progressBar = new JProgressBar(SwingConstants.HORIZONTAL);
  progressBar.setIndeterminate(true);
  contentPane.add(progressBar, BorderLayout.CENTER);
  JButton button = new JButton("Cancel");
  button.addActionListener(e -> cancel(false));
  contentPane.add(button, BorderLayout.SOUTH);
  dialog.setContentPane(contentPane);
  dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
  dialog.addWindowListener(new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent e) {
      cancel(false);
    }
  });
  dialog.pack();
  dialog.setLocationRelativeTo(solutionPanel.getSolverAndPersistenceFrame());
}

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

dialog.setVisible(false);
 startFileLoadingThread(filters, cFiles);
});
add.addActionListener(e -> {
 fileFilterPanel.add(getNewFilter());
 dialog.pack();
});
cancel.addActionListener(e -> dialog.setVisible(false));
dialog.getRootPane().setDefaultButton(okay);
dialog.pack();
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);

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

JButton showDialogButton = new JButton("Text Button");
showDialogButton.addActionListener(new ActionListener()
{
 public void actionPerformed(ActionEvent e)
 {
  // display/center the jdialog when the button is pressed
  JDialog d = new JDialog(frame, "Hello", true);
  d.setLocationRelativeTo(frame);
  d.setVisible(true);
 }
});

代码示例来源:origin: apache/pdfbox

private JDialog createJumpDialog()
  dialog.setLocationRelativeTo(this);
  final JLabel nowLabel = new JLabel("Present index: " + selectedIndex);
  final JLabel label = new JLabel("Index to go:");
  contentPanel.add(inputPanel);
  dialog.getContentPane().add(contentPanel);
  dialog.pack();
  return dialog;

代码示例来源:origin: groovy/groovy-core

FIND_REPLACE_DIALOG.pack();
    FIND_REPLACE_DIALOG.setLocationRelativeTo(frames[i]);
FIND_REPLACE_DIALOG.setVisible(true);
FIND_FIELD.requestFocusInWindow();

代码示例来源:origin: entertailion/Fling

public void run() {
    progressDialog.setLocationRelativeTo(FlingFrame.this);
    progressDialog.setTitle(message);
    progressDialog.setVisible(true);
  }
});

代码示例来源:origin: GoldenGnu/jeveassets

private void centerWindow() {
  jWindow.pack();
  jWindow.setLocationRelativeTo(jWindow.getParent());
}

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

public int show(JFrame frame) {
  dialog = new JDialog(frame, "Save Changes", true);
  Container contentPane = dialog.getContentPane();
  contentPane.setLayout(new BorderLayout());
  contentPane.add(this, BorderLayout.CENTER);
  dialog.setResizable(false);
  dialog.pack();
  dialog.setLocationRelativeTo(frame);
  dialog.getRootPane().setDefaultButton(saveButton);
  dialog.setVisible(true);
  dialog.dispose();
  return selectedValue;
}

代码示例来源:origin: org.swinglabs/swingx-ws

public boolean isServerTrusted(String host, X509Certificate cert) {
    accepted = false;
    
    JDialog dlg = createDialog();
    //populate the fields
    messagePane.setText(MessageFormat.format(message, host));
    //show the dialog
    dlg.setLocationRelativeTo(null);
    dlg.setVisible(true);
    
    return accepted;
  }
}

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

JDialog dialog = new CustomDialog(...);
dialog.pack();
dialog.setLocationRelativeTo( parentFrame );

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

public void display2() {
  JDialog dialog = new JDialog(null, "Title", ModalityType.APPLICATION_MODAL);
  dialog.getContentPane().add(this);
  dialog.pack();
  dialog.setLocationRelativeTo(null);
  txt2.requestFocusInWindow();
  dialog.setVisible(true);
 }

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

JDialog dialog = new JDialog(your_frame_reference, "Licence"); 
dialog .setModal(true); 
dialog .setLocationRelativeTo(null); 
dialog. getContentPane().add(new JLabel(your_text);
dialog .setVisible(true);

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

public void save(String fileName) throws IOException, PrintException {
  JDialog dialog = new JDialog();
  Container contentPane = dialog.getContentPane();
  ((JComponent) contentPane).setBorder(BorderFactory.createEmptyBorder(
      10, 10, 10, 10));
  contentPane.add(this);
  contentPane.setBackground(Color.white);
  dialog.pack();
  dialog.setLocationRelativeTo(null);
  dialog.dispose();
  GraphicsSupport.saveImage(this, fileName);
}

代码示例来源:origin: org.jodd/jodd-wot

protected void getFocusBack() {
  Toolkit.getDefaultToolkit().beep();
  super.setVisible(false);
  super.pack();
  super.setLocationRelativeTo(owner);
  super.setVisible(true);
}

代码示例来源:origin: MrCrayfish/ModelCreator

private static void showDialog(JDialog dialog)
{
  dialog.setLocationRelativeTo(null);
  dialog.setVisible(true);
  dialog.requestFocusInWindow();
}

相关文章

JDialog类方法