Article View: borland.public.jbuilder.java.swing
Article #246Re: JPanel.repaint( ) omited by the "drawing system"
From: Paul Furbacher [TeamB]
Date: Wed, 11 Apr 2007 05:02
Date: Wed, 11 Apr 2007 05:02
129 lines
5268 bytes
5268 bytes
Does this do what you want -- a value is updated after
closing a message pane?
package repaint_issue;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/** Shows that you don't have to do anything to update
* the UI after showing a JOptionPane.showXXXDialog()
*/
public class Frame1
extends JFrame {
JLabel jLabel1 = new JLabel();
JTextField tf = new JTextField();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JButton quitButton = new JButton();
JButton showButton = new JButton();
public Frame1() {
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(gridBagLayout1);
jLabel1.setText("Date: ");
quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
quitButton_actionPerformed(actionEvent);
}
});
showButton.setText("Show message");
showButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
showButton_actionPerformed(actionEvent);
}
});
quitButton.setText("Quit");
this.getContentPane().add(showButton,
new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(12, 12, 11, 0), 0, 0));
this.getContentPane().add(quitButton,
new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
, GridBagConstraints.EAST, GridBagConstraints.NONE,
new Insets(12, 0, 11, 11), 0, 0));
this.getContentPane().add(jLabel1,
new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(12, 12, 0, 8), 0, 0));
this.getContentPane().add(tf, new GridBagConstraints(1, 1, 2, 1,
1.0, 0.0
, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
new Insets(12, 0, 0, 11), 322, 0));
}
public static void main(String[] args) {
Frame1 frame1 = new Frame1();
frame1.pack();
frame1.setVisible(true);
}
public void quitButton_actionPerformed(ActionEvent actionEvent) {
System.exit(0);
}
public void showButton_actionPerformed(ActionEvent actionEvent) {
String date = new Date().toString();
JOptionPane.showMessageDialog(this, "A message" + date);
tf.setText(date);
}
}
If so, you don't have to invoke any kind of repaint or update.
Hiroshi Nakata wrote:
> When a Java app calls repaint() after JOptionPane.show***Dialog(),
> the repaint() is ignored because closing the dlg triggers a repaint() from
> the system, and the Java "drawing system" skips the 1st request (from the
> Java app) and executes only the 2nd (from the system).
>
> This leaves some region unmodified in a panel (to which repaint() is
> triggered)
> because the repaint() from the system repaints only 'dirty' region (ie
> region
> covered by the dlg). Here is a situation:
>
> 1)call repaint() to draw into a JPanel, jpnl, ie in jpnl.paintComponent(),
> g.draw***() are called.
> 2)call JOptionPane.show***Dialog() which is covering jpnl.
> 3)close the dlg, triggering jpnl.repaint() by the system
> 4)set some change (according to the inputs in the dlg) into effects in jpnl
> when drawn (such as new lines added)
> 5)call jpnl.repaint() to see the change.
>
> Result is that 5) is not executed by the "drawing system" because of the
> same call, jpnl.repaint(), in 3).
>
> How can we force the "drawing system" not to skip consecutive repaint()
> calls?
> Or am I missing something?
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Technical Details
Message-ID:
<461c6bba$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<46170d67$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,46b9de0c8529390 X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 11 Apr 2007 01:02:11 -0400 From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com> Organization: Reverse Alchemy, Inc. User-Agent: Thunderbird 1.5.0.10 (Macintosh/20070221) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: JPanel.repaint( ) omited by the "drawing system" References: <46170d67$1@newsgroups.borland.com> In-Reply-To: <46170d67$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.142.194.228 Message-ID: <461c6bba$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1176267706 69.142.194.228 (10 Apr 2007 22:01:46 -0800) Lines: 129 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail