Article View: borland.public.jbuilder.java.swing
Article #248Re: JPanel.repaint( ) omited by the "drawing system"
From: Hiroshi Nakata
Date: Fri, 13 Apr 2007 06:07
Date: Fri, 13 Apr 2007 06:07
176 lines
7270 bytes
7270 bytes
Thank you Paul for replying to my question. I am aware that all Swing/AWT
components
(in Container) which are entirely or partially in the dirty region will be
automatically
redrawn by super.paintComponent() [which is typically called at the very
beggining
of jpnl.paintComponent().] Therefore if no g.draw***()s are needed in jpnl,
no need to
call jpnl.repaint(). Your example is exactly that. But when jpnl doesn't
have any such
components but needs to be drawn with g.draw***(), things are different
because
super.paintComponent() won't draw anything but clear the panel in that case.
I think
g.draw***()s are still executed, but drawn only inside the dirty region. So
jpnl.repaint()
needs to be called from the app. Then when this 2nd repaint() is skipped by
the drawing
subsystem, such change (as drawing a line longer) by app is not shown in
jpnl.
I remember reading statements about 'amalgamating' drawing events in the
subsystem
for Java efficiency (in terms of speed) in some article long time ago.
Reading ahead
those events and making into 1 event. And I thought, skipping the 2nd
repaint() is one
of those 'so-cleaver' steps taken in the subsystem.
Currently I set 'redraw' button in my app to overcome this difficulty but I
consider it
too awkward and undesirable. Sometimes when a graphic object (=specific to
my
app) is opened and drawn, lines are drawn a couple of lines upper at some
point
(thus forms a y direction step/jump), which is obviously caused by those
'so-cleaver'
steps in the subsytem, I think. So I needed this 'redraw' button for that
reason, too.
"Paul Furbacher [TeamB]" <pfurbacher@mac.com> wrote in message
news:461c6bba$1@newsgroups.borland.com...
> 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:
<461ef32c$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<46170d67$1@newsgroups.borland.com> <461c6bba$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 Reply-To: "Hiroshi Nakata" <hiroshinakata@hotmail.com> From: "Hiroshi Nakata" <hiroshinakata@hotmail.com> Newsgroups: borland.public.jbuilder.java.swing References: <46170d67$1@newsgroups.borland.com> <461c6bba$1@newsgroups.borland.com> Subject: Re: JPanel.repaint( ) omited by the "drawing system" Date: Thu, 12 Apr 2007 23:07:24 -0700 Lines: 178 Organization: N/A X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 74.119.19.143 Message-ID: <461ef32c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1176433452 74.119.19.143 (12 Apr 2007 20:04:12 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail