1.
2.能达到视觉效果,在点击执行的时候remove再重新加进去就可以了。
至于3也是根据触发事件来动态调整版面的位置。

解决方案 »

  1.   

    to cyicecream:
      是我没看懂还是你没明白我的意思?可惜没法贴图,要不就一目了然了
    经过过程1,2,3后,jButton1和jButton2重叠区域的归属权是有争议的,重叠区域由jButton1和jButton2各画了一部分其实重叠部分应该都属于jButton1的,但是由于操作2让jButton2将重叠区域重画了(没有裁剪),但操作3中jButton3又部分重画了重叠区域,所以导致了这个问题
      

  2.   

    为何这个问题都没有人回答???我想这应该是每个做JavaGUI开发的人都会遇到的问题,
    如果一个GUI系统没有了裁剪,那么它的应用一定是很局限的,
    难道这么容易发现的问题却没有一个人观察过吗???
      

  3.   

    原贴(附图)见:news://news.newsfan.net Java组(潦潦草草)
      

  4.   

    代码就是JBuilder9生成的,会有问题吗?
    import javax.swing.*;
    import java.awt.event.*;
    import com.borland.jbcl.layout.*;
    import java.awt.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */
    class MyListRenderer extends JLabel implements ListCellRenderer
    {
      public Component getListCellRendererComponent(
          JList list,
          Object value,
          int index,
          boolean isSelected,
          boolean cellHasFocus)
      {
        setText(value.toString());
        setBackground(isSelected ? Color.red : Color.white);
        setForeground(isSelected ? Color.white : Color.black);
        return this;
      }
    }public class TestFrame extends JFrame {
      XYLayout xYLayout1 = new XYLayout();
      JButton jButton1 = new JButton();
      JButton jButton2 = new JButton();
      JButton jButton3 = new JButton();  public TestFrame() {
        setTitle("TestFrame");
        setSize(300,200);
        addWindowListener(new WindowAdapter()
        {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        }
        );
        try {
          jbInit();
          myInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public static void main(String[] args) {
        TestFrame testFrame = new TestFrame();
        testFrame.show();
      }
      private void jbInit() throws Exception {
        jButton1.setAlignmentX((float) 0.0);
        jButton1.setText("jButton1");
        jButton1.addActionListener(new TestFrame_jButton1_actionAdapter(this));
        this.getContentPane().setBackground(SystemColor.control);
        this.setLocale(java.util.Locale.getDefault());
        this.getContentPane().setLayout(xYLayout1);
        jButton2.setActionCommand("jButton1");
        jButton2.setText("jButton2");
        jButton2.addActionListener(new TestFrame_jButton2_actionAdapter(this));
        jButton3.setText("jButton3");
        jButton3.addActionListener(new TestFrame_jButton3_actionAdapter(this));
        this.getContentPane().add(jButton1,     new XYConstraints(0, 0, 100, 50));
        this.getContentPane().add(jButton2,    new XYConstraints(50, 25, 100, 50));
        this.getContentPane().add(jButton3,  new XYConstraints(100, 50, 100, 50));
      }
      private void myInit() throws Exception {
      }  void jButton1_actionPerformed(ActionEvent e) {
        System.out.print(jButton1.getVisibleRect());
      }  void jButton2_actionPerformed(ActionEvent e) {
        System.out.print(jButton2.getVisibleRect());
      }  void jButton3_actionPerformed(ActionEvent e) {
        System.out.print(jButton3.getVisibleRect());
      }
    }class TestFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {
      TestFrame adaptee;  TestFrame_jButton1_actionAdapter(TestFrame adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
      }
    }class TestFrame_jButton2_actionAdapter implements java.awt.event.ActionListener {
      TestFrame adaptee;  TestFrame_jButton2_actionAdapter(TestFrame adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
      }
    }class TestFrame_jButton3_actionAdapter implements java.awt.event.ActionListener {
      TestFrame adaptee;  TestFrame_jButton3_actionAdapter(TestFrame adaptee) {
        this.adaptee = adaptee;
      }
      public void actionPerformed(ActionEvent e) {
        adaptee.jButton3_actionPerformed(e);
      }
    }
      

  5.   

    java 中没有 Z-order, Z-order 是 Windows GUI 编成的概念。
      

  6.   

    replace XYLayout with BoxLayout, everything is ok. J2sdk doesn't have XYLayout.
    I'll try your program with JB later. I've not installed JB now.
      

  7.   

    to: jacklondon(jacklondon) 
    谁说Java中没有Z-Order,Z-Order是任何GUI都应该有的概念
    推荐你看看《Java2图形设计》
      

  8.   

    to wobelisk() 我换成BoxLayout2,但几个按钮并不重叠了,所以不能看出效果
    我用的是JBuilder9,待会儿我再试试GridLayout,看看行不行
      

  9.   

    没有JB9,我用Absolute Position得到了同样的效果。楼主实验一下,看是否一致。
    //注释调与XYLayout相关的语句,添加下列:
        this.getContentPane().setLayout(null);
        this.getContentPane().add(jButton1); 
        jButton1.setBounds(0, 0,100,50);
        this.getContentPane().add(jButton2);
        jButton2.setBounds(50, 25,100,50);
        this.getContentPane().add(jButton3);
        jButton3.setBounds(100, 50,100,50);
    其他都保留。
    终于明白老兄的问题了。这与Java 的Clipping真的没有关系。造成贴图效果的原因是Java没有及时重绘界面。事实上,一旦Java Application重获Focus后,就重绘了界面,楼主所说的效果就没了。
    Java 的Z-Order好象倒是听说过在不同JVM上有差异。
    重叠的Component,不同语言处理得也是不同的。我觉得这不是Java的Bug。
    VB最偷懒,Overlap的几个Button, Z-Order是不变的
    VC和Java基本一致。你的这个效果,VC也有(设计时首尾两个Button盖中间的Button),而且比JAVA笨的是,VC重获焦点也没重绘Clipping区域。Java不记忆所有Button的相对Z-Order,比VC又弱了一点。
    总结:不是Bug.
      

  10.   

    to wobelisk():
    首先,我非常感谢你有兴趣来和我探讨这个问题,Java不是我所熟悉的,我深入研究Swing是为了吸收其精华,用于嵌入式系统的GUI。对于你的解释,我觉得有两个疑点:首先,点击下Z序(被遮挡)的jButton2,其Z序是否真的发生了改变?
        做一个试验:1、点击jButton2,让其变为顶层窗口(可能只是视觉上的变化)2、用一个窗口将其覆盖,然后关掉覆盖窗口,引发其重画,(这时jButton2依然是焦点)jButton2的Z序(视觉上)又恢复成原来的状态。
        答案:所以我觉得有可能Z序没有改变,只是重画引起的效果其次,如果上面jButton2的Z序真的变为最上层了,那么为什么还会出现下面的问题?
        将jButton1和jButton2的重叠部分遮挡,引发重画,发现二者重叠区域被jButton1覆盖了,如果真如老兄所说jButton2的Z-Order变成了topmost,那么这个问题不应该出现
      

  11.   

    刚试了一下VC中的相同情况,出现了完全相似的结果这是我完全没有想到的,突然一下子觉得思维很混乱,我需要重新考虑一下自己对GUI的理解可能老兄对这个问题的理解比我清晰,希望继续指教
    工作忙,三天没上来了,如果愿意,我们可以以邮件交流:
    [email protected]
      

  12.   

    再一次在VC中试验了一下:我给三个按钮加上了WS_CLIPSIBLINGS属性,结果就正确了,我想问问老兄,Java中是否有类似的属性?多谢了,我一直想找出JFC中关于裁剪部分的代码,这个问题可以成为我的突破口……
      

  13.   

    to achive similar effect, use JLayeredPane to contain the buttons.JLayeredPane jp=new JLayeredPane();
    jp.setLayout(null);
    jp.add(b1,new Integer(1));
    jp.add(b2,new Integer(2));
    jp.add(b3,new Integer(3));the depth of LayeredPane is similar to the Z-Order.