请高手指点一下,我想做一个窗口和jbuilderx中的messages窗口一样。当把它拖出来之后,一直浮动在主窗口之上,但是还是可以对主窗口进行操作的。我试了javaswing 的一些组件,应该不是jDialog,jframe之类的组件,很有可能是jtoolbar和jwindow这两个组件写出来的。
解决方案 »
- 导出excel自动分行,列宽,行高设定的问题
- Java字符创赋值的问题
- 静态类和方法什么时候被装载?
- 一个Java源文件中的多个类如何处理?
- 子类继承父类为什么不行?
- 请问:jdom生成xml中(UTF-8),部分中文字符出现乱码,是怎么回事呢
- 谁能告诉我jdk+tomcat到底该怎么配??? 快受不了了
- 一份英国电子商务本科生的习题,大家来帮帮忙,说说算法就可以:)
- javascript 如何判断网页中某个 checkbox 有没有被选中?
- ResultSet 中有COUNT 方法吗?我想取出RESULTSET 中结果集的数目?
- 在用RandomAccessFile时写入文本文件(TXT)的数据是乱码(中文)英文是OK
- 求教路径问题
用非模式的对话框,对话框可以到frame后面去,不符合要求用JInternalFrame窗口的话,不能超出主窗口,也不符合要求
import javax.swing.JDesktopPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JFrame;
import javax.swing.KeyStroke;import java.awt.event.*;
import java.awt.*;/*
* InternalFrameDemo.java is a 1.4 application that requires:
* MyInternalFrame.java
*/
public class InternalFrameDemo extends JFrame
implements ActionListener {
JDesktopPane desktop; public InternalFrameDemo() {
super("InternalFrameDemo"); //Make the big window be indented 50 pixels from each edge
//of the screen.
int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset,
screenSize.width - inset*2,
screenSize.height - inset*2); //Set up the GUI.
desktop = new JDesktopPane(); //a specialized layered pane
createFrame(); //create first "window"
setContentPane(desktop);
setJMenuBar(createMenuBar()); //Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
} protected JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar(); //Set up the lone menu.
JMenu menu = new JMenu("Document");
menu.setMnemonic(KeyEvent.VK_D);
menuBar.add(menu); //Set up the first menu item.
JMenuItem menuItem = new JMenuItem("New");
menuItem.setMnemonic(KeyEvent.VK_N);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_N, ActionEvent.ALT_MASK));
menuItem.setActionCommand("new");
menuItem.addActionListener(this);
menu.add(menuItem); //Set up the second menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_Q, ActionEvent.ALT_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem); return menuBar;
} //React to menu selections.
public void actionPerformed(ActionEvent e) {
if ("new".equals(e.getActionCommand())) { //new
createFrame();
} else { //quit
quit();
}
} //Create a new internal frame.
protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
frame.setVisible(true); //necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
} //Quit the application.
protected void quit() {
System.exit(0);
} /**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Display the window.
frame.setVisible(true);
} public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
import java.awt.*;/* Used by InternalFrameDemo.java. */
public class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30; public MyInternalFrame() {
super("Document #" + (++openFrameCount),
true, //resizable
true, //closable
true, //maximizable
true);//iconifiable //...Create the GUI and put it in the window... //...Then set the window size or call pack...
setSize(300,300); //Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
}
}