Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JDesktopPane/JInternalFrame - question re: closing frames and repainting  RSS feed

 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSplitPane that contains a JPanel as one of its subcomponents.

This JPanel (BorderLayout) contains a toolbar (another JPanel) and a JDesktopPane.

The JDesktopPane contains 0-many JInternalFrames all of which are rather simple (i.e., I don't do anything real fancy).

The toolbar, among other things, contains a button that when clicked will close all of the JInternalFrames in the JDesktopPane.




If I click on an individual frame's close button (X) in the top-right corner, without having written one line of code to handle this, the JSplitPane.paint(Graphics) method is called.

If I click on the Close All button in my toolbar, my myToolbarPane.actionPerformed() method is called (see below) and the JSplitPane.paint(Graphics) method is NOT called (using either implementation).

public void actionPerformed(ActionEvent e) {
// Implementation #1
myDesktopPane.removeAll();
myDesktopPane.repaint();

// Implementation #2
// JInternalFrame[] elementFrames = myDesktopPane.getAllFrames();
// for (int i = 0; i < elementFrames.length; i++) {
// elementFrames[i].doDefaultCloseAction();
// }
}


The question I am throwing out to everyone is ultimately why is the JSplitPane.paint(Graphics) method NOT called when the Close All button is clicked?

It just so happens that I need a panel in the other part of the JSplitPane to repaint when a JInternalFrame is closed. This is not happening when I click on the Close All button. Also know that I tried having the panel that needs to update listen to/observe when the frames are closed and have confirmed it is being notified and it is calling revalidate() and repaint() but nothing happens because it thinks the height and width of the panel is 0.

Thanks!!!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't ever know for sure when the paint() method is going to be called by the VM. With Swing components you should always use paintComponent method instead.
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I totally agree!

I overrode the paintComponent() method for the panel that I need to update and I am not calling the JSplitPane.paint() method myself....for whatever reason somewhere swing is calling the JSplitPane.paint() method when an individual JInternalFrame is closed by clicking the X button in the top-right corner. What I need to do for my Close All button is mimic the clicking on the X button on all JInternalFrames AND GET THE SAME BEHAVIOR (which at this minute I am not because the calls I know how to make to close the windows don't result in swings triggering of the JSplitPane.paint() method).

p.s. I did override the paint() method in my various panels just to see what was being called and when but these implementations simply logged a message and called super.paint(g).
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how exactly are you closing all the JInternalFrames with the click of a button? Are you just using the removeAll to remove the components?

What happens if you iterate over each one and dispose of the frame instead?
[ May 18, 2005: Message edited by: Gregg Bolinger ]
 
Kelly Dolan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I explained this in my first post (my code is redisplayed below). When my toolbar button is clicked, the actionPerformed() method is called. First, I tried telling my JDesktopPane to simply remove all of its components (Implementation #1). Second, I tried iterating over each JInternalFrame and telling each to close (Implementation #2). Both result in the closing of all JInternalFrames.

public void actionPerformed(ActionEvent e) {
// Implementation #1
myDesktopPane.removeAll();
myDesktopPane.repaint();

// Implementation #2
// JInternalFrame[] elementFrames = myDesktopPane.getAllFrames();
// for (int i = 0; i < elementFrames.length; i++) {
// elementFrames[i].doDefaultCloseAction();
// }
}
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kelly Dolan:
I explained this in my first post (my code is redisplayed below). When my toolbar button is clicked, the actionPerformed() method is called. First, I tried telling my JDesktopPane to simply remove all of its components (Implementation #1). Second, I tried iterating over each JInternalFrame and telling each to close (Implementation #2). Both result in the closing of all JInternalFrames.

public void actionPerformed(ActionEvent e) {
// Implementation #1
myDesktopPane.removeAll();
myDesktopPane.repaint();

// Implementation #2
// JInternalFrame[] elementFrames = myDesktopPane.getAllFrames();
// for (int i = 0; i < elementFrames.length; i++) {
// elementFrames[i].doDefaultCloseAction();
// }
}


Sorry, I should read more closely. I'll play around a bit and see what I can figure out.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!