本文整理了Java中javax.swing.JDialog
类的一些代码示例,展示了JDialog
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JDialog
类的具体详情如下:
包路径:javax.swing.JDialog
类名称:JDialog
暂无
代码示例来源:origin: stanfordnlp/CoreNLP
private void doEncodingPrompt(final String encoding, final String oldEncoding) {
final JPanel encodingPanel = new JPanel();
encodingPanel.setLayout(new BoxLayout(encodingPanel, BoxLayout.PAGE_AXIS));
JLabel text = new JLabel("<html>A head finder or tree reader was selected that has the default encoding " + encoding
+ "; this differs from " + oldEncoding + ", which was being used. If the encoding is changed, all newly loaded" +
JPanel textPanel = new JPanel(new BorderLayout());
textPanel.setPreferredSize(new Dimension(100,100));
textPanel.add(text);
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: libgdx/libgdx
@Override
public void run () {
JPanel panel = new JPanel(new FlowLayout());
JPanel textPanel = new JPanel() {
public boolean isOptimizedDrawingEnabled () {
return false;
};
textPanel.setLayout(new OverlayLayout(textPanel));
panel.add(textPanel);
pane.selectInitialValue();
dialog.addWindowFocusListener(new WindowFocusListener() {
dialog.setModal(true);
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
dialog.dispose();
代码示例来源:origin: stackoverflow.com
final JDialog d = new JDialog();
d.setSize(200,200);
d.setLocationRelativeTo(null);
d.setVisible(true);
代码示例来源:origin: stackoverflow.com
final JDialog d = new JDialog();
d.setSize(200, 200);
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final Dimension screenSize = toolkit.getScreenSize();
final int x = (screenSize.width - d.getWidth()) / 2;
final int y = (screenSize.height - d.getHeight()) / 2;
d.setLocation(x, y);
d.setVisible(true);
代码示例来源:origin: stackoverflow.com
final JDialog frame = new JDialog(parentFrame, frameTitle, true);
frame.getContentPane().add(panel);
frame.pack();
frame.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);
final JDialog dialog = new JDialog(win, "Dialog", ModalityType.APPLICATION_MODAL);
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: magefree/mage
private void initDialog() {
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(0, 15, 0, 0);
c.weightx = 0.10;
JLabel text = new JLabel("Choose color for your deck:");
mainPanel.add(text, c);
colorsChooser.setEnabled(false);
selectedColors = (String) colorsChooser.getSelectedItem();
dlg.setVisible(false);
MageFrame.getPreferences().put("genDeckColor", selectedColors);
});
btnCancel = new JButton("Cancel");
btnCancel.addActionListener(e -> {
dlg.setVisible(false);
selectedColors = null;
});
JOptionPane optionPane = new JOptionPane(mainPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, options[1]);
dlg = optionPane.createDialog("Generating Deck");
dlg.setResizable(false);
dlg.setVisible(true);
dlg.dispose();
代码示例来源: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: camunda/camunda-bpm-platform
public LogFactor5LoadingDialog(JFrame jframe, String message) {
super(jframe, "LogFactor5", false);
JPanel bottom = new JPanel();
bottom.setLayout(new FlowLayout());
JPanel main = new JPanel();
main.setLayout(new GridBagLayout());
wrapStringOnPanel(message, main);
getContentPane().add(main, BorderLayout.CENTER);
getContentPane().add(bottom, BorderLayout.SOUTH);
show();
}
//--------------------------------------------------------------------------
代码示例来源:origin: geotools/geotools
frame = new JInternalFrame(title);
window = frame;
content = new JPanel(); // Pour avoir un fond opaque
parentSize = desktop.getSize();
frame.setContentPane(content);
} else {
final JDialog dialog;
dialog = new JDialog((Frame) null, title);
window = dialog;
content = (JComponent) dialog.getContentPane();
parentSize = Toolkit.getDefaultToolkit().getScreenSize();
dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
dialog.setResizable(false);
cancel = new JButton(resources.getString(VocabularyKeys.CANCEL));
cancel.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
final JPanel panel = new JPanel(new GridLayout(2, 1));
panel.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(VMARGIN, HMARGIN, VMARGIN, HMARGIN),
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame("DialogClosing");
JPanel mainPanel = new JPanel();
mainPanel.add(new JButton(new MyAction(frame, JDialog.DISPOSE_ON_CLOSE, "DISPOSE_ON_CLOSE")));
mainPanel.add(new JButton(new MyAction(frame, JDialog.HIDE_ON_CLOSE, "HIDE_ON_CLOSE")));
mainPanel.add(new JButton(new MyAction(frame, JDialog.DO_NOTHING_ON_CLOSE, "DO_NOTHING_ON_CLOSE")));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
dialog = new JDialog(frame, title, false);
dialog.setDefaultCloseOperation(defaultCloseOp);
dialog.setPreferredSize(new Dimension(300, 200));
dialog.pack();
dialog.setVisible(true);
代码示例来源:origin: libgdx/libgdx
@Override
public void run () {
JPanel panel = new JPanel(new FlowLayout());
JPanel textPanel = new JPanel() {
public boolean isOptimizedDrawingEnabled () {
return false;
};
textPanel.setLayout(new OverlayLayout(textPanel));
panel.add(textPanel);
pane.selectInitialValue();
dialog.addWindowFocusListener(new WindowFocusListener() {
dialog.setVisible(true);
dialog.dispose();
代码示例来源:origin: stackoverflow.com
editorComponent = new JButton();
editorComponent.setBackground(Color.white);
editorComponent.setBorderPainted(false);
popup.setLocation(p.x, p.y + editorComponent.getSize().height);
popup.show();
fireEditingStopped();
textArea.getInputMap().put(keyStroke, "none");
JScrollPane scrollPane = new JScrollPane( textArea );
getContentPane().add( scrollPane );
JPanel buttons = new JPanel();
buttons.add( ok );
buttons.add( cancel );
getContentPane().add(buttons, BorderLayout.SOUTH);
pack();
getRootPane().setDefaultButton( ok );
setVisible( false );
table.getColumnModel().getColumn(1).setCellEditor( popupEditor );
代码示例来源:origin: stackoverflow.com
import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Alignment;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.LayoutStyle.ComponentPlacement;import javax.swing.border.EmptyBorder;import javax.swing.filechooser.FileFilter;import javax.swing.filechooser.FileNameExtensionFilter;public class ConfigureDialog extends JDialog implements ActionListener{private static final long serialVersionUID=1L;private final JPanel contentPanel=new JPanel();private JTextField driverPathTextField;private JLabel lblDriverPath;private JButton btnBrowse;public static void main(String[]args){try{ConfigureDialog dialog=new ConfigureDialog(new JFrame());dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true);}catch(Exception e){e.printStackTrace();}}
public ConfigureDialog(JFrame parent){super(parent,"",true);if(parent!=null){Dimension parentSize=parent.getSize();Point p=parent.getLocation();setLocation(p.x+parentSize.width+100,p.y+parentSize.height/1);}
setBounds(100,100,479,141);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5,5,5,5));getContentPane().add(contentPanel,BorderLayout.CENTER);{lblDriverPath=new JLabel("Driver Path : ");}
{driverPathTextField=new JTextField(System.getProperty("web.ie.driver"));driverPathTextField.setColumns(10);}
btnBrowse=new JButton("Browse");GroupLayout gl_contentPanel=new GroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addContainerGap().addComponent(lblDriverPath).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(btnBrowse).addComponent(driverPathTextField,GroupLayout.DEFAULT_SIZE,207,Short.MAX_VALUE)).addContainerGap()));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(5).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(driverPathTextField,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE).addComponent(lblDriverPath)).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnBrowse).addContainerGap(21,Short.MAX_VALUE)));contentPanel.setLayout(gl_contentPanel);{JPanel buttonPane=new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane,BorderLayout.SOUTH);{JButton okButton=new JButton("OK");okButton.setActionCommand("OK");okButton.addActionListener(this);buttonPane.add(okButton);getRootPane().setDefaultButton(okButton);}
{JButton cancelButton=new JButton("Cancel");cancelButton.setActionCommand("Cancel");cancelButton.addActionListener(this);buttonPane.add(cancelButton);}}
btnBrowse.addActionListener(this);}@Override
public void actionPerformed(ActionEvent e){if("Cancel".contains(e.getActionCommand())){dispose();}else if("Browse".contains(e.getActionCommand())){JFileChooser fileopen=new JFileChooser();FileFilter filter=new FileNameExtensionFilter("exe file","exe");fileopen.addChoosableFileFilter(filter);fileopen.setAcceptAllFileFilterUsed(false);fileopen.setFileFilter(filter);fileopen.setFileSelectionMode(JFileChooser.FILES_ONLY);int ret=fileopen.showOpenDialog(this);if(ret==JFileChooser.APPROVE_OPTION){File file=fileopen.getSelectedFile();System.out.println(file);driverPathTextField.setText(file.getPath());}}else if("OK".contains(e.getActionCommand())){System.setProperty("web.ie.driver",driverPathTextField.getText());dispose();}}}
代码示例来源:origin: apache/pdfbox
private JDialog createJumpDialog()
final JDialog dialog = new JDialog(SwingUtilities.windowForComponent(this), "Jump to index");
dialog.setLocationRelativeTo(this);
final JLabel nowLabel = new JLabel("Present index: " + selectedIndex);
final JLabel label = new JLabel("Index to go:");
JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
panel.add(nowLabel);
JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
inputPanel.add(label);
inputPanel.add(field);
contentPanel.add(panel);
contentPanel.add(inputPanel);
dialog.getContentPane().add(contentPanel);
dialog.pack();
return dialog;
代码示例来源:origin: stackoverflow.com
JPanel pnl = new JPanel(new BorderLayout());
pnl.add(new JLabel("Click outside this dialog in the parent frame to close it"), BorderLayout.NORTH);
JButton btn = new JButton("Click Me");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
pnl.add(btn, BorderLayout.CENTER);
this.setContentPane(pnl);
this.pack();
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(owner);
this.setAlwaysOnTop(true);
this.addWindowFocusListener(new WindowFocusListener() {
return;
ClickAwayDialog.this.setVisible(false);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame parent = new JFrame();
parent.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
parent.setSize(300, 300);
parent.setLocationByPlatform(true);
parent.setVisible(true);
ClickAwayDialog dlg = new ClickAwayDialog(parent);
dlg.setVisible(true);
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame("Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(pane);
frame.pack();
frame.setVisible(true);
JPanel pane = new JPanel(new BorderLayout());
pane.add(newLabel(labelText));
pane.add(newButton("Open dialog"), BorderLayout.SOUTH);
return pane;
final JButton button = new JButton(label);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Window parentWindow = SwingUtilities.windowForComponent(button);
JDialog dialog = new JDialog(parentWindow);
dialog.setLocationRelativeTo(button);
dialog.setModal(true);
dialog.add(newPane("Label in dialog"));
dialog.pack();
dialog.setVisible(true);
代码示例来源:origin: stanfordnlp/CoreNLP
final JDialog dialog = new JDialog(frame, "Jar File Chooser", true);
dialog.setLocation(location);
final JList fileList = new JList(new Vector<>(files));
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JButton okay = new javax.swing.JButton();
okay.setText("Okay");
okay.setToolTipText("Okay");
okay.addActionListener(evt -> dialog.setVisible(false));
JButton cancel = new javax.swing.JButton();
cancel.setText("Cancel");
cancel.addActionListener(evt -> {
fileList.clearSelection();
dialog.setVisible(false);
});
dialog.setLayout(gridbag);
constraints.weighty = 1.0;
gridbag.setConstraints(scroll, constraints);
dialog.add(scroll);
constraints.weighty = 0.0;
gridbag.setConstraints(okay, constraints);
dialog.add(okay);
dialog.add(cancel);
dialog.pack();
代码示例来源:origin: stackoverflow.com
private JDialog dialog = new JDialog();
private BackgroundPanel panel = new BackgroundPanel();
getScreenInsets(dialog.getGraphicsConfiguration());
int taskBarSize = scnMax.bottom;
panel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.NORTH;
JButton b = new JButton(new AbstractAction("x") {
dialog.dispose();
b.setMargin(new Insets(1, 4, 1, 4));
b.setFocusable(false);
panel.add(b, constraints);
dialog.setUndecorated(true);
dialog.setSize(300, 100);
dialog.setLocation(screenSize.width - dialog.getWidth(),
screenSize.height - taskBarSize - dialog.getHeight());
lpg = new LinearGradientPaint(0, 0, 0, dialog.getHeight() / 2,
new float[]{0f, 0.3f, 1f}, new Color[]{new Color(0.8f, 0.8f, 1f),
new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f)});
dialog.setContentPane(panel);
dialog.setVisible(true);
内容来源于网络,如有侵权,请联系作者删除!