在运行java桌面应用程序时,主窗口打开后,点击某个控件时弹出一个新窗口,就会在任务栏中显示两个java图标。我想在java运行时桌面中可以显示多个窗口,但任务栏中只显示一个图标,怎么实现呀?我从CSDN中查到在shell中加入两行代码:final int hand = shell.handle;OS.SetWindowLong(hand, OS.GWL_EXSTYLE, OS.WS_EX_CAPTIONOKBTN);就可以实现,但是我的代码就不行呀,

解决方案 »

  1.   

    主窗口用 Frame
    子窗口用 Dialog
      

  2.   

    [Quote=引用 3 楼 king_spf 的回复:]
    引用 1 楼 wcwtitxu 的回复:
    主窗口用 Frame 
    子窗口用 Dialog 
     
      

  3.   

    主窗口用Frame,其他窗口用对话框Dialog
      

  4.   

    一个JFrame 其他的都用Jdialog不就可以了吗?
      

  5.   

    我是用swt designer开发的,如何是这样的话,代码都的改了呀!
      

  6.   

    主窗口代码:
    package mytest;import java.awt.Frame;
    import java.awt.MouseInfo;
    private static final long serialVersionUID = 1L;
    private List list_2;
    protected Shell shell;
            public static void main(String[] args) {
    try {
    ListViewTest window = new ListViewTest();
    window.open();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    public void open() {
    final Display display = Display.getDefault();
    createContents();
    shell.open();
    shell.layout();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    }
            protected void createContents() {
                shell = new Shell();
    shell.setVisible(false);
    shell.setFont(SWTResourceManager.getFont("宋体", 12, SWT.NONE));
    shell.setForeground(SWTResourceManager.getColor(255, 255, 255));
    shell.setSize(367, 375);
    shell.setText("SWT Application");


    list_2 = new List(shell, SWT.V_SCROLL | SWT.BORDER);
    list_2.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
    list_2.setForeground(SWTResourceManager.getColor(255, 255, 255));
    list_2.setBackground(SWTResourceManager.getColor(0, 0, 0));
    list_2.setBounds(60, 29, 153, 292);
    for (int loopIndex = 100; loopIndex < 200; loopIndex++){ 
    list_2.add("Item " + loopIndex);
    }
    list_2.addSelectionListener(new SelectionListener( )
    {
    public void widgetSelected(SelectionEvent event)
    {
    //list_2.setSelection(arg0)
    System.out.println ("AAAAAAAAAAAAAAAAAA");
    int selections[] = list_2.getSelectionIndices ( );
    String outText = "";
    for (int loopIndex = 0; loopIndex < selections.length; loopIndex++) {
    outText += selections[loopIndex] + " ";
    }
    System.out.println ("You selected: " + outText);
    java.awt.Point mousePoint = MouseInfo.getPointerInfo().getLocation(); 
    /**开始调用DiaoLog*/
    DialogListView myDialogview = new DialogListView(shell);
    myDialogview.setShellx(event.x+mousePoint.x);
    myDialogview.setShelly(event.y+mousePoint.y);
    myDialogview.open();
    }
    public void widgetDefaultSelected(SelectionEvent event)
    {
    System.out.println ("BBBBBBBBBBBBBBBBBBBBBB");
    int [] selections = list_2.getSelectionIndices ( );
    String outText = "";
    for (int loopIndex = 0; loopIndex < selections.length; loopIndex++) {
    outText += selections[loopIndex] + " ";
    }
    System.out.println ("You selected: " + outText);
    }

    });

    }
    }
      

  7.   

    呈上,子窗口:
    package mytest;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.MouseEvent;
    import org.eclipse.swt.events.MouseMoveListener;
    import org.eclipse.swt.events.MouseTrackAdapter;
    import org.eclipse.swt.internal.win32.OS;
    import org.eclipse.swt.widgets.Canvas;
    import org.eclipse.swt.widgets.Dialog;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;import others.windows.MovieInfo;import com.baseinfo.WebserveBaseInfo;
    import com.swtdesigner.SWTResourceManager;
    public class DialogListView extends Dialog {
    protected Object result;
    private Text text;
    protected Shell shell;

    private int shellx;
    private int shelly; public int getShellx() {
    return shellx;
    } public void setShellx(int shellx) {
    this.shellx = shellx;
    } public int getShelly() {
    return shelly;
    } public void setShelly(int shelly) {
    this.shelly = shelly;
    } public DialogListView(Shell parent, int style) {
    super(parent, style);
    //open();
    } public DialogListView(Shell parent) {
    this(parent, SWT.NONE);
    //open();
    }
    public Object open() {
    createContents();
    shell.open();
    shell.layout();
    Display display = getParent().getDisplay();
    while (!shell.isDisposed()) {
    if (!display.readAndDispatch())
    display.sleep();
    }
    return result;
    }
    protected void createContents() {
    shell = new Shell(SWT.APPLICATION_MODAL | SWT.NO_TRIM);
    shell.setVisible(false);
    final int hand = shell.handle;
    OS.SetWindowLong(hand, OS.GWL_EXSTYLE, OS.WS_EX_CAPTIONOKBTN);
    shell.addMouseTrackListener(new MouseTrackAdapter() {
    public void mouseExit(final MouseEvent arg0) {
    shell.close();
    }
    });
    shell.setBackgroundImage(SWTResourceManager.getImage(MovieInfo.class, "/LiveNowimages/Info.png"));
    shell.setSize(154, 198);
    shell.setText("SWT Application");
    shell.setFocus();
    shell.setLocation(this.getShellx(), this.getShelly());
    shell.addMouseMoveListener(new MouseMoveListener() {
    public void mouseMove(final MouseEvent e) {
    shell.close();
    }
    });

    WebserveBaseInfo webmoveidinfo = new WebserveBaseInfo();
    final Canvas canvas = new Canvas(shell,SWT.NONE);
    canvas.setRedraw(true);
    canvas.setBackgroundImage(SWTResourceManager.getImage(DialogListView.class, "/LiveNowimages/02.jpg"));


    canvas.setBounds(10, 10, 134, 70);

    //String TvName = "片名:"+this.getTvname();
    //System.out.println("TvName value is:"+TvName);
    final Label label = new Label(shell, SWT.NONE);
    label.setForeground(SWTResourceManager.getColor(255, 255, 255));
    label.setBackground(SWTResourceManager.getColor(0, 0, 0));
    label.setText("我是谁");
    label.setBounds(10, 85, 134, 12);

    //String Tvmainman = "主演:"+this.getMainman();
    //System.out.println("Tvmainman value is:"+Tvmainman);
    final Label label_1 = new Label(shell, SWT.NONE);
    label_1.setForeground(SWTResourceManager.getColor(255, 255, 255));
    label_1.setBackground(SWTResourceManager.getColor(0, 0, 0));
    label_1.setText("成龙");
    label_1.setBounds(10, 99, 135, 12);

    //String TvCount = this.getTvCount();
    //System.out.println("TvCount value is:"+TvCount);
    text = new Text(shell, SWT.WRAP | SWT.READ_ONLY | SWT.MULTI);
    text.setRedraw(true);
    text.setText("内容运营主要由业务处理系统、运营支撑系统、内容管理系统、话单服务系统等组成。主要负责相关视音频节目播放系统和监管系统的建设和管理,包含业务逻辑管理和处理、业务数据处理等基本业务处理功能;视音频节目内容的组织、转播、制作、审核、存储、管理和发布、播出控制、相关视听节目内容的安全等内容管理功能;系统管理、用户管理、服务管理、业务管理、DRM管理、统计分析、认证鉴权、计费帐务、对帐结算等有关用户资料及业务资料管理的运营支撑功能; IPTV话单的查询和统计等话单服务功能;以及与其他系统的相关接口功能。");
    text.setForeground(SWTResourceManager.getColor(255, 255, 255));
    text.setBackground(SWTResourceManager.getColor(0, 0, 0));
    text.setBounds(10, 114, 134, 74);
    }}在主窗口调用子窗口是还是不行呀,高手速速进来给指点一下。
      

  8.   

    遇到浮动窗口设计时,就不可以用dialog啦