JDK-4248716 : JLayeredPane setEnabled(false) ineffective on its children
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1999-06-22
  • Updated: 2000-04-14
  • Resolved: 2000-04-14
Related Reports
Duplicate :  
Description

Name: vi73552			Date: 06/22/99


This may be the a duplicate of 1257395, and akin to 4121207
but I thought I'd bring it to your attention.  
JLayeredPane.setEnabled(false) is ineffective for recursively
disabling its children.

import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;


public class disablePanelBug extends JFrame {
  public disablePanelBug(){
    getContentPane().setLayout(null);

    layeredPaneWithListener mainPanel = new layeredPaneWithListener();
		GridBagLayout gb = new GridBagLayout();
		mainPanel.setLayout(gb);

		GridBagConstraints leftPanelConst = new GridBagConstraints();
    leftPanelConst.weightx = 0.0;
		leftPanelConst.weighty = 0.0;
		leftPanelConst.gridx = 0;
		leftPanelConst.gridy = 0;
    leftPanelConst.fill = GridBagConstraints.VERTICAL;
    
		panelWithListener leftPanel = new panelWithListener();

		leftPanel.setBackground(Color.red);
		JLabel leftLabel = new JLabel("A Panel");
		leftPanel.add(leftLabel);
    gb.setConstraints(leftPanel,leftPanelConst);
    mainPanel.add(leftPanel);

    GridBagConstraints tableConst = new GridBagConstraints();
    tableConst.weightx = 1.0;
		tableConst.weighty = 1.0;
		tableConst.gridx = 1;
		tableConst.gridy = 0;
    tableConst.fill = GridBagConstraints.BOTH;
		Vector rows = new Vector();
		Vector row1 = new Vector();
		row1.addElement("row1 col1");
		row1.addElement("row1 col2");
		row1.addElement("row1 col3");
    Vector row2 = new Vector();
		row2.addElement("row2 col1");
		row2.addElement("row2 col2");
		row2.addElement("row2 col3");
		Vector row3 = new Vector();
		row3.addElement("row3 col1");
		row3.addElement("row3 col2");
		row3.addElement("row3 col3");

		rows.addElement(row1);
		rows.addElement(row2);
		rows.addElement(row3);

    Vector cols = new Vector();
		cols.addElement("Column1");
		cols.addElement("Column2");
		cols.addElement("Column3");

		DefaultTableModel tm = new DefaultTableModel(rows,cols);
		JTable table = new JTable(tm);
		JScrollPane s = new JScrollPane(table);
		s.setColumnHeaderView(table.getTableHeader());
    
    s.setBackground(Color.green);
    gb.setConstraints(s,tableConst);
    mainPanel.add(s);
		
    mainPanel.setSize(545,183);
		mainPanel.setLocation(0,0);
    getContentPane().add(mainPanel);

		mainPanel.setEnabled(false);

    setSize(547,185);
		show();
  }
  public static void main(String args[]){
    new disablePanelBug();
  }
}

class panelWithListener extends JPanel implements MouseMotionListener {
	public panelWithListener () {
		addMouseMotionListener(this);
	}
	public void mouseDragged(MouseEvent event) {
		System.out.println("Mouse dragged JPanel");
	}			
	public void mouseMoved(MouseEvent event) {
		System.out.println("Mouse moved JPanel");
	}
}

class layeredPaneWithListener extends JLayeredPane implements MouseMotionListener {
	public layeredPaneWithListener () {
		addMouseMotionListener(this);
	}
	public void mouseDragged(MouseEvent event) {
		System.out.println("Mouse dragged JLayeredPane");
	}			
	public void mouseMoved(MouseEvent event) {
		System.out.println("Mouse moved JLayeredPane");
	}
}
(Review ID: 84690) 
======================================================================

Comments
WORK AROUND Name: vi73552 Date: 06/22/99 Programmatically disable each child object. ======================================================================
11-06-2004

EVALUATION Yes, I can reproduce this with jdk1.3. I wasn't sure this was a bug, so I checked: since other containers recursively disable their children, so should JLayeredPane. hania.gajewska@Eng 1999-09-21
21-09-1999