JPanel visible rectangle area notification

HI... does anyone know how can i know when the visible rectangle of a Jpanel is increased or decreased?Sarjay
[130 byte] By [Sarjaya] at [2007-11-26 12:22:24]
# 1
if the visible area changes when the panel's container changes size, add a componentListener to the container.
Michael_Dunna at 2007-7-7 15:15:37 > top of Java-index,Archived Forums,Socket Programming...
# 2

ComponentListener does not work in my case. Consider a situation where the panel size is 1200x1200 and visible rectangle is 200x300 initially when split bar is moved Visble rectangle of the panel increase or decreases. In this case the panel size remains the same. sample code is given below

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.event.ComponentEvent;

import java.awt.event.ComponentListener;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JSplitPane;

public class VisibleRect extends JFrame{

private JPanel centerPanel = null;

private JSplitPane splitPane1 = null;

public VisibleRect() {

intiComp();

}

private void intiComp() {

centerPanel = new JPanel();

centerPanel.setBackground(Color.white);

centerPanel.setPreferredSize(new Dimension(1200, 1200));

centerPanel.addComponentListener(new ComponentListener() {

public void componentHidden(ComponentEvent e) {

System.out.println("componentHidden");

}

public void componentShown(ComponentEvent e) {

System.out.println("componentShown");

}

public void componentMoved(ComponentEvent e) {

System.out.println("componentMoved");

}

public void componentResized(ComponentEvent e) {

System.out.println("componentResized");

}

});

splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(centerPanel), new JLabel());

add(splitPane1, BorderLayout.CENTER);

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

setSize(200, 300);

setVisible(true);

}

/**

* @param args

*/

public static void main(String[] args) {

new VisibleRect();

}

}

Sarjaya at 2007-7-7 15:15:37 > top of Java-index,Archived Forums,Socket Programming...
# 3

Based on you original question how where supposed to know that you where talking about a JSplitPane?

Why is it so difficult to ask a meaningful question with all the details the first time so we don't waste our time guessing what you are talking about?

You could try adding a PropertyChangeListener to the split pane and listen for changes in the divider location.

camickra at 2007-7-7 15:15:37 > top of Java-index,Archived Forums,Socket Programming...
# 4
Sorry for giving improper information...in my first timeIs it possible to know the cahnge in visible rectangle by adding any listener to the centerPanel?Sarjay
Sarjaya at 2007-7-7 15:15:37 > top of Java-index,Archived Forums,Socket Programming...
# 5
> Is it possible to know the cahnge in visible rectangle by adding any listener to the centerPanelI just gave you a solution. If you know the location of the divider you can calculate the viewable size of the panel.
camickra at 2007-7-7 15:15:37 > top of Java-index,Archived Forums,Socket Programming...