有问题的地方: mainPane.setRightComponent(popup); //   为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因package com;import   java.awt.*;   import   javax.swing.*;   import com.JInternalFrame1.PopupListener;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("打开");
    fileMenu.add(openFile);
    popup.add(fileMenu);  
    /*建立一个新的JDesktopPane并加入于contentPane中
     */
    desktopPane = new JDesktopPane(); 
    contentPane.add(desktopPane);    // setSize(350, 350); 
    show(); 
    
   
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);contentPane.add(mainPane,"Center");   
mainPane.setRightComponent(popup); //   为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因
  
//this.setDefaultCloseOperation(3);   
  
this.setSize(800,600);   
  
MouseListener popupListener = new PopupListener(popup);
openFile.addActionListener(
     new ActionListener() { 
 
     public void actionPerformed(ActionEvent e) { 
     dd(); 
    
     } 
     } 
     ); 
panel1.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(260,250);
    internalFrame.setSize(100,100); 
    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);  
    
    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[])   
{   
new   SplitTest();   
}   
  
  
}
 

解决方案 »

  1.   

    package test;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("打开");
    fileMenu.add(openFile);
    popup.add(fileMenu); /*
     * 建立一个新的JDesktopPane并加入于contentPane中
     */
    desktopPane = new JDesktopPane();
    contentPane.add(desktopPane); // setSize(350, 350);
    show(); 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);
    JPanel p = new JPanel();
    p.setBackground(Color.red);
    contentPane.add(mainPane, "Center");
    p.add(popup);
    mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因


    mainPane.setLeftComponent(tree);
    // this.setDefaultCloseOperation(3); this.setSize(800, 600); MouseListener popupListener = new PopupListener(popup);
    openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
    dd(); }
    }); panel1.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(260, 250);
    internalFrame.setSize(100, 100);
    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); 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[]) {
    new SplitTest();
    }}
      

  2.   

    package test;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("打开");
    fileMenu.add(openFile);

    popup.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);
    JPanel p = new JPanel();
    p.setBackground(Color.red);
    contentPane.add(mainPane, "Center");
    p.add(popup);

    mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因


    mainPane.setLeftComponent(tree);
    // 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(260, 250);
    internalFrame.setSize(100, 100);
    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); 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);
    }}
      

  3.   

    p.setBackground(Color.red); 这句去掉了,我刚才运行了只有一个右键了,什么也不显示啊。
      

  4.   

    点击右键菜单 出现在右边但是不会影响左边的树,就是左右两边彻底分开显示不影响分割线的移动,
    右键菜单怎么没有了,你看看是不是这样。
    Jpane  怎么设置一下
    有一个setRightComponent 这个属性好像不行
      

  5.   

    package test;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("打开");
    fileMenu.add(openFile);

    popup.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");
    p.add(popup);

    mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因

    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(260, 250);
    internalFrame.setSize(100, 100);
    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); 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);
    }}
      

  6.   

    package test;import java.awt.*;import javax.swing.*;import java.awt.event.*;
    import java.beans.PropertyVetoException;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("打开");
    fileMenu.add(openFile);

    popup.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");
    p.add(popup);

    mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因

    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(260, 250);
    internalFrame.setSize(100, 100);
    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);
    JFrame f = new JFrame();
    f.getContentPane().add(desktopPane);
    f.setVisible(true);
    f.setSize(400,200);
    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);
    }}
      

  7.   

    你要设置弹出位置设一下f.setLocale(l)就好了
      

  8.   

    对了 f.setLocale(l) f 是不是
    JInternalFrame internalFrame = new JInternalFrame("ying", true, true, true, true); 
    的窗体啊!
      

  9.   

    设置了 internalFrame.setLocation(360, 450); 
    还是不出来 试过了!!
      

  10.   

    package test;import java.awt.*;import javax.swing.*;import java.awt.event.*;
    import java.beans.PropertyVetoException;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("打开");
    fileMenu.add(openFile);

    popup.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");
    p.add(popup);

    mainPane.setRightComponent(p); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动 什么原因

    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(260, 250);

    // 取得JInternalFrame的Content Pane,用以加入新的组件。
    //Container icontentPane = internalFrame.getContentPane();
    JTextArea textArea = new JTextArea();
    JButton b = new JButton("Internal Frame Button");
    /*
     * 将JTextArea与JButton对象加入JInternalFrame中。由此呆知,JInteranlFrame加入组件
     * 的方式与JFrame是一模一样。
     */

    internalFrame.add(textArea, "Center");
    internalFrame.add(b, "South");
    // 将JInternalFrame加入JDesktopPane中,如此一来,即使产生很多JInternalFrame,JDesktopPane也
    // 能将它们之间的关系管理得相当良好。
    desktopPane.add(internalFrame);
    internalFrame.setSize(400,200);
    internalFrame.setVisible(true);
    desktopPane.setSize(400,200);
    desktopPane.setVisible(true);
    desktopPane.setSize(800,600);
    JFrame f = new JFrame();
    f.getContentPane().add(desktopPane);



    try {
    internalFrame.setSelected(true);
    } catch (java.beans.PropertyVetoException ex) {
    System.out.println("Exception while selecting");
    }

    f.setSize(800,600);
    f.setVisible(true);
    } 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);
    }}
      

  11.   

    package test;import java.awt.*;import javax.swing.*;import java.awt.event.*;
    import java.beans.PropertyVetoException;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("打开");
    fileMenu.add(openFile); popup.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); // p.setBackground(Color.red);
    contentPane.add(mainPane, "Center");
    desktopPane.add(popup); mainPane.setRightComponent(desktopPane); // 为什么加了这句就不能拉动分割条例 两个三角不能拉动
    // 什么原因 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(); }
    }); desktopPane.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(260, 250); // 取得JInternalFrame的Content Pane,用以加入新的组件。
    // Container icontentPane = internalFrame.getContentPane();
    JTextArea textArea = new JTextArea();
    JButton b = new JButton("Internal Frame Button");
    /*
     * 将JTextArea与JButton对象加入JInternalFrame中。由此呆知,JInteranlFrame加入组件
     * 的方式与JFrame是一模一样。
     */ internalFrame.add(textArea, "Center");
    internalFrame.add(b, "South");
    // 将JInternalFrame加入JDesktopPane中,如此一来,即使产生很多JInternalFrame,JDesktopPane也
    // 能将它们之间的关系管理得相当良好。
    desktopPane.add(internalFrame);
    internalFrame.setSize(400, 200);
    internalFrame.setVisible(true);
    //desktopPane.setSize(400, 200);
    desktopPane.setVisible(true);
    //desktopPane.setSize(800, 600); 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);
    }}
      

  12.   

    是不是和上个帖子的问题一样啊?一样在这里也贴一个我自己写的内部窗体的例子,楼主可运行看看package demo;import java.awt.Component;
    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());
    }
    });
    }
    }