import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;public class himmain extends JFrame {
private JComboBox jComboBoxHimData = null; //him data
private JMenu jMenuFile = new JMenu();
private JMenuItem jMenuFileLoad = new JMenuItem();
private JMenuBar jMenuBar1 = new JMenuBar();
public himmain() {
super();
initialize();
}
private void initialize() {
jComboBoxHimData = new JComboBox();
jComboBoxHimData.setEditable(true);
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jComboBoxHimData);
jMenuFile.setText("File(F)");
jMenuFileLoad.setText("Load(L)");
jMenuFile.add(jMenuFileLoad);
jMenuBar1.add(jMenuFile);
this.setJMenuBar(jMenuBar1);
jMenuFileLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileLoad_actionPerformed(e);
}
});
this.setSize(200,200);
}
public void jMenuFileLoad_actionPerformed(ActionEvent e) { //TODO LOAD
himload hl=new himload();
hl.show();
}
public static void main(String args[]) {
himmain f = new himmain();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.show();
}}import java.awt.FlowLayout;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;public class himload extends JFrame {
private JLabel jlabel1=null;
private JTextField jtextfield1=null;
public himload() {
super();
initialize();
}
public void initialize() {
jlabel1 = new JLabel();
jlabel1.setText("HIM_HEAD_DA");
jtextfield1=new JTextField();
jtextfield1.setText("DA");
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jlabel1);
this.getContentPane().add(jtextfield1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(100,100);
}
}
主窗口中有一个JCOMBOX,且setEditable(true). 当点击菜单LOAD时,显示的子窗口(jframe)不能置顶显示. 那位高人知道如何让子窗口能置顶显示? 前提条件:不能将子窗口改成JDIALOG类型.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;public class himmain extends JFrame {
private JComboBox jComboBoxHimData = null; //him data
private JMenu jMenuFile = new JMenu();
private JMenuItem jMenuFileLoad = new JMenuItem();
private JMenuBar jMenuBar1 = new JMenuBar();
public himmain() {
super();
initialize();
}
private void initialize() {
jComboBoxHimData = new JComboBox();
jComboBoxHimData.setEditable(true);
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jComboBoxHimData);
jMenuFile.setText("File(F)");
jMenuFileLoad.setText("Load(L)");
jMenuFile.add(jMenuFileLoad);
jMenuBar1.add(jMenuFile);
this.setJMenuBar(jMenuBar1);
jMenuFileLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileLoad_actionPerformed(e);
}
});
this.setSize(200,200);
}
public void jMenuFileLoad_actionPerformed(ActionEvent e) { //TODO LOAD
himload hl=new himload();
hl.show();
}
public static void main(String args[]) {
himmain f = new himmain();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.show();
}}import java.awt.FlowLayout;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;public class himload extends JFrame {
private JLabel jlabel1=null;
private JTextField jtextfield1=null;
public himload() {
super();
initialize();
}
public void initialize() {
jlabel1 = new JLabel();
jlabel1.setText("HIM_HEAD_DA");
jtextfield1=new JTextField();
jtextfield1.setText("DA");
this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(jlabel1);
this.getContentPane().add(jtextfield1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(100,100);
}
}
主窗口中有一个JCOMBOX,且setEditable(true). 当点击菜单LOAD时,显示的子窗口(jframe)不能置顶显示. 那位高人知道如何让子窗口能置顶显示? 前提条件:不能将子窗口改成JDIALOG类型.
在你的jMenuFileLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileLoad_actionPerformed(e);
}
});
里面添加一行代码:
jMenuFileLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileLoad_actionPerformed(e);
jComboBoxHimData.setEditable(false);
}
});
搞定
另外,我发现,若在主窗口再追加一个控件如JTEXTFIELD, 在打开LOAD子窗口前,先将焦点从JCOMBOX移到JTEXTFIELD,这样显示的子窗口也可以置顶,这样的代码如何写呢.
hl.setAlwaysOnTop(alwaysOnTop);
hl.setVisible(true);
建議類名還是首字母大寫的好, 看著比較清楚...
在子窗口中加上
new Shell(/*SWT.SHELL_TRIM | SWT.PRIMARY_MODAL | SWT.BORDER */);
这三个特性:SWT.SHELL_TRIM | SWT.PRIMARY_MODAL | SWT.BORDER,真的很管用: