package com;
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class SplitTest extends JFrame { JDesktopPane desktopPane;
// int count = 1;
JMenu fileMenu; JPopupMenu popup; public SplitTest() {
super("SplitFrame Test");
init();
} public void init() { Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
popup = new JPopupMenu();// 创建jPopupMenuOne对象
fileMenu = new JMenu("dfdf"); JMenuItem openFile = new JMenuItem("打开");
popup.add(fileMenu); fileMenu.add(openFile); /*
* 建立一个新的JDesktopPane并加入于contentPane中
*/
desktopPane = new JDesktopPane();
contentPane.add(desktopPane); // setSize(350, 350);
this.setVisible(true); JTree tree = new JTree();
JPanel panel1 = new JPanel();
//panel1.setBackground(Color.red); final JSplitPane mainPane = new JSplitPane();
// JSplitPane.HORIZONTAL_SPLIT,
// tree, panel1
mainPane.setContinuousLayout(true);
mainPane.setOneTouchExpandable(true); // mainPane.setEnabled(false);
// centerPane.setEnabled(false); // mainPane.add(popup);
// panel1.add(popup);
// panel1.setBounds(200,200,500, 400);
JScrollPane p = new JScrollPane();
//p.setBackground(Color.red);
contentPane.add(mainPane, "Center");
mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因
p.add(popup); JScrollPane tp = new JScrollPane(tree);
mainPane.setLeftComponent(tp);
// this.setDefaultCloseOperation(3); this.setSize(800, 600); MouseListener popupListener = new PopupListener(popup); openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
dd(); }
});
p.addMouseListener(popupListener);
// centerPane.setDividerLocation(0.2); // ======================================
// mainPane.setDividerLocation(0.2); // ====================================== // this.repaint();
} /*
* 产生一个可关闭、可改变大小、具有标题、可最大化与最小化的Internal Frame.
*/
public void dd() {
JInternalFrame internalFrame = new JInternalFrame("ying", true, true,
true, true);
internalFrame.setLocation(360, 250);
internalFrame.setSize(200, 200);
internalFrame.setVisible(true);
internalFrame.show();
// 取得JInternalFrame的Content Pane,用以加入新的组件。
Container icontentPane = internalFrame.getContentPane();
JTextArea textArea = new JTextArea();
JButton b = new JButton("Internal Frame Button");
/*
* 将JTextArea与JButton对象加入JInternalFrame中。由此呆知,JInteranlFrame加入组件
* 的方式与JFrame是一模一样。
*/
icontentPane.add(textArea, "Center"); //icontentPane.add(b, "South");
// 将JInternalFrame加入JDesktopPane中,如此一来,即使产生很多JInternalFrame,JDesktopPane也
// 能将它们之间的关系管理得相当良好。
desktopPane.add(internalFrame); System.out.println("到这里来了吗!!!!!!!!!!!!!!!!!");try {
internalFrame.setSelected(true);
} catch (java.beans.PropertyVetoException ex) {
System.out.println("Exception while selecting");
}
} class PopupListener extends MouseAdapter { JPopupMenu popupMenu; PopupListener(JPopupMenu popupMenu) { this.popupMenu = popupMenu; } public void mousePressed(MouseEvent e) { showPopupMenu(e); } public void mouseReleased(MouseEvent e) { showPopupMenu(e); } private void showPopupMenu(MouseEvent e) { if (e.isPopupTrigger()) {// 如果当前事件与鼠标事件相关,则弹出菜单 popupMenu.show(e.getComponent(), e.getX(), e.getY()); } }// 结束showPopupMenu } public static void main(String args[]) {
SplitTest t = new SplitTest();
t.setVisible(true);
}
}
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class SplitTest extends JFrame { JDesktopPane desktopPane;
// int count = 1;
JMenu fileMenu; JPopupMenu popup; public SplitTest() {
super("SplitFrame Test");
init();
} public void init() { Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
popup = new JPopupMenu();// 创建jPopupMenuOne对象
fileMenu = new JMenu("dfdf"); JMenuItem openFile = new JMenuItem("打开");
popup.add(fileMenu); fileMenu.add(openFile); /*
* 建立一个新的JDesktopPane并加入于contentPane中
*/
desktopPane = new JDesktopPane();
contentPane.add(desktopPane); // setSize(350, 350);
this.setVisible(true); JTree tree = new JTree();
JPanel panel1 = new JPanel();
//panel1.setBackground(Color.red); final JSplitPane mainPane = new JSplitPane();
// JSplitPane.HORIZONTAL_SPLIT,
// tree, panel1
mainPane.setContinuousLayout(true);
mainPane.setOneTouchExpandable(true); // mainPane.setEnabled(false);
// centerPane.setEnabled(false); // mainPane.add(popup);
// panel1.add(popup);
// panel1.setBounds(200,200,500, 400);
JScrollPane p = new JScrollPane();
//p.setBackground(Color.red);
contentPane.add(mainPane, "Center");
mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因
p.add(popup); JScrollPane tp = new JScrollPane(tree);
mainPane.setLeftComponent(tp);
// this.setDefaultCloseOperation(3); this.setSize(800, 600); MouseListener popupListener = new PopupListener(popup); openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
dd(); }
});
p.addMouseListener(popupListener);
// centerPane.setDividerLocation(0.2); // ======================================
// mainPane.setDividerLocation(0.2); // ====================================== // this.repaint();
} /*
* 产生一个可关闭、可改变大小、具有标题、可最大化与最小化的Internal Frame.
*/
public void dd() {
JInternalFrame internalFrame = new JInternalFrame("ying", true, true,
true, true);
internalFrame.setLocation(360, 250);
internalFrame.setSize(200, 200);
internalFrame.setVisible(true);
internalFrame.show();
// 取得JInternalFrame的Content Pane,用以加入新的组件。
Container icontentPane = internalFrame.getContentPane();
JTextArea textArea = new JTextArea();
JButton b = new JButton("Internal Frame Button");
/*
* 将JTextArea与JButton对象加入JInternalFrame中。由此呆知,JInteranlFrame加入组件
* 的方式与JFrame是一模一样。
*/
icontentPane.add(textArea, "Center"); //icontentPane.add(b, "South");
// 将JInternalFrame加入JDesktopPane中,如此一来,即使产生很多JInternalFrame,JDesktopPane也
// 能将它们之间的关系管理得相当良好。
desktopPane.add(internalFrame); System.out.println("到这里来了吗!!!!!!!!!!!!!!!!!");try {
internalFrame.setSelected(true);
} catch (java.beans.PropertyVetoException ex) {
System.out.println("Exception while selecting");
}
} class PopupListener extends MouseAdapter { JPopupMenu popupMenu; PopupListener(JPopupMenu popupMenu) { this.popupMenu = popupMenu; } public void mousePressed(MouseEvent e) { showPopupMenu(e); } public void mouseReleased(MouseEvent e) { showPopupMenu(e); } private void showPopupMenu(MouseEvent e) { if (e.isPopupTrigger()) {// 如果当前事件与鼠标事件相关,则弹出菜单 popupMenu.show(e.getComponent(), e.getX(), e.getY()); } }// 结束showPopupMenu } public static void main(String args[]) {
SplitTest t = new SplitTest();
t.setVisible(true);
}
}
恩 我发过去!!
import javax.swing.*;
import java.awt.event.*;public class SplitTest extends JFrame { JDesktopPane desktopPane; // int count = 1;
JMenu fileMenu; JPopupMenu popup; public SplitTest() {
super("SplitFrame Test");
init();
} public void init() { Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
popup = new JPopupMenu();// 创建jPopupMenuOne对象
fileMenu = new JMenu("dfdf"); JMenuItem openFile = new JMenuItem("打开");
popup.add(fileMenu); fileMenu.add(openFile); /*
* 建立一个新的JDesktopPane并加入于contentPane中
*/
desktopPane = new JDesktopPane();
contentPane.add(desktopPane); // setSize(350, 350);
// this.setVisible(true); JTree tree = new JTree();
JPanel panel1 = new JPanel();
// panel1.setBackground(Color.red); final JSplitPane mainPane = new JSplitPane();
// JSplitPane.HORIZONTAL_SPLIT,
// tree, panel1
mainPane.setContinuousLayout(true);
mainPane.setOneTouchExpandable(true); // mainPane.setEnabled(false);
// centerPane.setEnabled(false); // mainPane.add(popup);
// panel1.add(popup);
// panel1.setBounds(200,200,500, 400);
JScrollPane p = new JScrollPane();
// p.setBackground(Color.red);
contentPane.add(mainPane, "Center"); mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因
p.add(popup); JScrollPane tp = new JScrollPane(tree);
mainPane.setLeftComponent(tp);
// this.setDefaultCloseOperation(3); this.setSize(800, 600); MouseListener popupListener = new PopupListener(popup); openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
dd(); }
});
p.addMouseListener(popupListener); // centerPane.setDividerLocation(0.2); // ======================================
// mainPane.setDividerLocation(0.2); // ====================================== // this.repaint();
} /*
* 产生一个可关闭、可改变大小、具有标题、可最大化与最小化的Internal Frame.
*/
public void dd() {
JInternalFrame internalFrame = new JInternalFrame("ying", true, true, true, true);
internalFrame.setLocation(360, 250);
internalFrame.setSize(200, 200);
internalFrame.setVisible(true);
internalFrame.show();
// 取得JInternalFrame的Content Pane,用以加入新的组件。
Container icontentPane = internalFrame.getContentPane();
JTextArea textArea = new JTextArea();
JButton b = new JButton("Internal Frame Button");
/*
* 将JTextArea与JButton对象加入JInternalFrame中。由此呆知,JInteranlFrame加入组件
* 的方式与JFrame是一模一样。
*/
icontentPane.add(textArea, "Center"); // icontentPane.add(b, "South");
// 将JInternalFrame加入JDesktopPane中,如此一来,即使产生很多JInternalFrame,JDesktopPane也
// 能将它们之间的关系管理得相当良好。
desktopPane.add(internalFrame); System.out.println("到这里来了吗!!!!!!!!!!!!!!!!!"); try {
internalFrame.setSelected(true);
} catch (java.beans.PropertyVetoException ex) {
System.out.println("Exception while selecting");
}
} class PopupListener extends MouseAdapter { JPopupMenu popupMenu; PopupListener(JPopupMenu popupMenu) { this.popupMenu = popupMenu; } public void mousePressed(MouseEvent e) { showPopupMenu(e); } public void mouseReleased(MouseEvent e) { showPopupMenu(e); } private void showPopupMenu(MouseEvent e) { if (e.isPopupTrigger()) {// 如果当前事件与鼠标事件相关,则弹出菜单 popupMenu.show(e.getComponent(), e.getX(), e.getY());
popupMenu.setPopupSize(200, 200);
} }// 结束showPopupMenu } public static void main(String args[]) {
SplitTest t = new SplitTest();
t.setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.JTree;public class DemoInnerFrame extends JApplet { private JTree tree; private JDesktopPane desktopPane; public DemoInnerFrame() {
super();
getContentPane().setLayout(null); final JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBounds(0, 0, 500, 375);
getContentPane().add(panel); final JSplitPane splitPane = new JSplitPane();
splitPane.setDividerLocation(150);
splitPane.setBounds(0, 5, 490, 370);
panel.add(splitPane); final JPanel panel_1 = new JPanel();
panel_1.setLayout(null);
splitPane.setLeftComponent(panel_1); tree = new JTree();
tree.setBounds(0, 0, 163, 358);
panel_1.add(tree); final JPanel panel_2 = new JPanel();
panel_2.setLayout(null);
splitPane.setRightComponent(panel_2); desktopPane = new JDesktopPane();
desktopPane.setBounds(0, 0, 472, 358);
panel_2.add(desktopPane); final JPopupMenu popupMenu = new JPopupMenu();
addPopup(desktopPane, popupMenu); final JMenuItem menuItem = new JMenuItem();
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
creatInnerFrame();
}
});
menuItem.setText("新建内部窗体");
popupMenu.add(menuItem);
setSize(520, 400); //
} public void creatInnerFrame() {
JInternalFrame internalFrame = new JInternalFrame("示例内部窗体", true, true,
true, true);
internalFrame.getContentPane().setLayout(null); internalFrame.setVisible(true);
internalFrame.setBounds(0, 0, 254, 334);
desktopPane.add(internalFrame); JPanel panel_3 = new JPanel();
panel_3.setLayout(null);
panel_3.setBounds(0, 0, 254, 334);
internalFrame.getContentPane().add(panel_3); JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "您点击了示例按钮!");
}
});
button.setText("示例按钮");
button.setBounds(43, 100, 100, 20);
panel_3.add(button);
} private static void addPopup(Component component, final JPopupMenu popup) {
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger())
showMenu(e);
} public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger())
showMenu(e);
} private void showMenu(MouseEvent e) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
});
}
}