我想知道爲什麼我們應該在對話框中寫入「null」?爲什麼我們應該在對話框中使用「null」?
str= JOptioPane.showMessageDialog(
parentComponent(null), // <--
messageStringExpression,
boxTitleString,
meeageType);
什麼時候我們要寫它? 我可以寫點別的嗎?
感謝所有
我想知道爲什麼我們應該在對話框中寫入「null」?爲什麼我們應該在對話框中使用「null」?
str= JOptioPane.showMessageDialog(
parentComponent(null), // <--
messageStringExpression,
boxTitleString,
meeageType);
什麼時候我們要寫它? 我可以寫點別的嗎?
感謝所有
,爲什麼我們要在對話框中寫入 「空」?
如果爲父級是null
(又名parentComponent(null)
),那麼的JDialog取決於不可見的窗口,並且將其放置在外觀和感覺相關的位置,如屏幕的中央。
我可以寫別的東西
當然,你可以添加有你想要一個像JButton的任何組件,....
一些示例:
private JButton btn_Save;
btn_Save = new JButton(save);
btn_Save.setText("Save Configuration");
btn_Save.setBounds(20, 459, 290, 25);
btn_Save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btn_Save) {
if(saveData()){
JOptionPane.showMessageDialog(btn_Save, "Event Configuration saved successfully!");
}
else{
JOptionPane.showMessageDialog(btn_Save, "Failed to save Event Configuration!");
}
}
}
在這針對null
的情況,對話框中心位於按鈕btn_Save
非常感謝 – user2849967
JOptionPane.showMessageDialog(parentComponent(null),message);
然後以desktop
爲中心對話框。
JOptionPane.showMessageDialog(someComponent,message);
對話框裏然後集中在someComponent
這裏是API文檔:http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html – AimanB