Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Best way to force a JComponent to repaint itself

Reply
Thread Tools

Best way to force a JComponent to repaint itself

 
 
Arne Vajhøj
Guest
Posts: n/a
 
      08-16-2008
zerg wrote:
> Peter Duniho wrote:
>> On Wed, 13 Aug 2008 22:30:57 -0700, zerg <(E-Mail Removed)> wrote:
>>> I DID look at the docs -- the JList and JComponent docs. Why would I
>>> be poking around in the AWT docs? I'm obviously using Swing.

>>
>> Because Swing is built on top of AWT.
>>
>> JComponent inherits Component. You can't understand JComponent
>> without understanding Component.

>
> The same mistake you've made several times before. You assume that I
> seek to thoroughly understand JComponent. I don't. I seek to use it in a
> particular way at this particular time.


Maybe you should start with some basic OOP.

The methods of a parent class is just as relevant for using a class
as the methods implemented in the sub class.

> There is no end-of-term exam. There is only whether or not, at the end
> of the day, they have gotten their work done and have not fallen behind
> any schedule that might apply. To whatever extent you waste their time
> with irrelevancies and to-you-fascinating side diversions such as
> learning the implementation and internals of a Java class in depth, you
> are doing them a disservice.


If you want to decide what type and form of advice you get, then I
will recommend hiring a consultant - for 200-300 USD/hr such a person
will provide you with exactly what you want.

If you want it for free, then you will need to live with what
can get.

Arne
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      08-16-2008
zerg wrote:
> Knute Johnson wrote:
>> Call repaint() and come back with a better attitude when it doesn't work.

>
> My attitude is fine.


Have you tried counting opinions on that ?

Arne
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      08-16-2008
zerg wrote:
> Peter Duniho wrote:
>> On Thu, 14 Aug 2008 02:49:09 -0700, zerg <(E-Mail Removed)> wrote:
>>> It isn't. However, nobody in this thread has done such a thing (at
>>> least, not yet). You have claimed otherwise, but your claim was a lie.

>>
>>> It looks like the API is missing a no-arg "repaint()" [...]

>>
>> What part about "It looks like the API is missing a no-arg repaint()"
>> is not a claim that what you were looking for doesn't exist?

>
> It's a claim that what I was looking for doesn't exist IN THAT
> ALPHABETIC LIST OF JCOMPONENT METHODS.
>
> It turns out to exist, SOMEWHERE ELSE.


Is it too much to assume that people read all the relevant
sections of a page ?

Arne
 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      08-16-2008
Arne Vajhøj wrote:
> zerg wrote:
>> Peter Duniho wrote:
>>> there is in fact a "no parameter" overload of the method (see below).

>>
>> In an AWT class, apparently, where I of course didn't go looking for
>> it since I'm working with Swing.

>
> It is is on the doc page for the class you are using also - all you
> need to do is scroll.


A link was. Buried in a dense mass of text that isn't very amenable to
skimming, no less.

>> If you'd prefer not to answer a question, for some particular reason,
>> you could always not post any kind of response to it at all. One thing
>> I will certainly not tolerate, however, is any sort of response that
>> implies, in front of a worldwide audience no less, that you think I'm
>> in some way incompetent. Stop doing that!

>
> Do you think [snipped]


Threats are wasted here, where there is no possible danger of physical
retribution.

Don't bother threatening me again.

>> In a place where I didn't look, and where I had no reason to look,
>> since it's in a completely different section of the API documentation.

>
> Same page.


"Same page" is a meaningless measure of locality when a single "page"
may be the equivalent of thirty or forty printed-book pages.
 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      08-16-2008
Arne Vajhøj wrote:
> zerg wrote:
>> Peter Duniho wrote:
>>> On Wed, 13 Aug 2008 22:30:57 -0700, zerg <(E-Mail Removed)> wrote:
>>>> I DID look at the docs -- the JList and JComponent docs. Why would I
>>>> be poking around in the AWT docs? I'm obviously using Swing.
>>>
>>> Because Swing is built on top of AWT.
>>>
>>> JComponent inherits Component. You can't understand JComponent
>>> without understanding Component.

>>
>> The same mistake you've made several times before. You assume that I
>> seek to thoroughly understand JComponent. I don't. I seek to use it in
>> a particular way at this particular time.

>
> Maybe you should start with some basic OOP.


Maybe you should learn some manners!

> The methods of a parent class is just as relevant for using a class
> as the methods implemented in the sub class.


That depends on whether the parent class was subclassed as a part of the
data type (X is a special sort of Y) or was subclassed solely for code
reuse. C++ has the concept of private inheritance; for better or worse,
Java does not. Delegation should probably be used when the purpose is
code reuse, but that doesn't mean that this advice is always followed.

>> To whatever extent you waste
>> their time with irrelevancies and to-you-fascinating side diversions
>> such as learning the implementation and internals of a Java class in
>> depth, you are doing them a disservice.

>
> If you want to decide what type and form of advice you get, then I
> will recommend hiring a consultant - for 200-300 USD/hr such a person
> will provide you with exactly what you want.


What? All I'm asking is that people here be polite and treat me with the
basic level of respect normally accorded all human beings interacting in
a civilized society. Are you suggesting that being polite is such an
onerous burden that politeness should cost actual money? My God!
 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      08-16-2008
Martien Verbruggen wrote:
> On Thu, 14 Aug 2008 01:30:57 -0400,
> zerg <(E-Mail Removed)> wrote:
>> Knute Johnson wrote:
>>> If you had looked at the docs you would have seen that the no-arg
>>> repaint() belongs to Component.

>> I DID look at the docs -- the JList and JComponent docs. Why would I be
>> poking around in the AWT docs? I'm obviously using Swing.

>
> In the Java documentation, just after the alphabetical list of methods
> under the heading 'Method Summary', there are lists of all methods that
> are inherited from each of the superclasses.


Yes, albeit hard to read ones; I've noticed.

Did you have some sort of a point here?

> but you should check all the possible lists of methods in
> that documentation.


Even when there are five or six of them like that one, densely packed,
with dozens of entries each, and virtually unreadable? A tidy grid with
down-then-across alphabetic order would have been a better design
choice, though still uncomfortably reminiscent of such old-fashioned
things as looking up names in a phone book.

A more interactive documentation reader might be nice. I've played
around a bit with Squeak and it has method categories and color-coding
features in its class browser widget. Something like this in the
Javadocs for more complex classes and APIs would be great, though it
would also be too much work to expect anything to happen anytime soon.

I'd suggest an added doc tag, @category name, to put with the @param,
@throws, etc. tags for methods and even with the @author for classes,
with any string allowed as the name; methods would be grouped and color
coded by category in the generated docs, and likewise classes in the
package overviews, with colors assigned somehow to the distinct category
names in the same class or package.

Links on class and package pages for each category name occurring
therein could provide a category-focused view, with a link back to the
main view. The category-focused view could include showing methods of
interest to subclassers (generally protected, but public ones to
override too), methods related to a particular use scenario (e.g.
user-induced repainting, custom painting, setting preferred dimensions,
and so forth as categories for JComponent), and the like.

Perhaps allowing a method to be in multiple categories would be useful.
The same public method might be a likely target for subclasses to
override usefully as well as having a particular category of use. Better
might be to have an additional tag, @overridetarget or similarly, and an
additional view that specifically focuses on protected and
@overridetarget methods and protected fields.
 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      08-16-2008
Arne Vajhøj wrote:
> zerg wrote:
>> Peter Duniho wrote:
>>> On Thu, 14 Aug 2008 02:49:09 -0700, zerg <(E-Mail Removed)> wrote:
>>>> It isn't. However, nobody in this thread has done such a thing (at
>>>> least, not yet). You have claimed otherwise, but your claim was a lie.
>>>
>>>> It looks like the API is missing a no-arg "repaint()" [...]
>>>
>>> What part about "It looks like the API is missing a no-arg repaint()"
>>> is not a claim that what you were looking for doesn't exist?

>>
>> It's a claim that what I was looking for doesn't exist IN THAT
>> ALPHABETIC LIST OF JCOMPONENT METHODS.
>>
>> It turns out to exist, SOMEWHERE ELSE.

>
> Is it too much to assume that people read all the relevant
> sections of a page ?


It is not too much to assume that people read all of the
OBVIOUSLY-RELEVANT sections of a page, no, particularly the main
alphabetic method listing.
 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      08-16-2008
Arne Vajhøj wrote:
> zerg wrote:
>> Knute Johnson wrote:
>>> Call repaint() and come back with a better attitude when it doesn't
>>> work.

>>
>> My attitude is fine.

>
> Have you tried counting opinions on that ?


Nope. Not interested. This is a technical discussion newsgroup, not a
popularity contest, anyway.
 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      08-16-2008
Arne Vajhøj wrote:
> zerg wrote:
>> Knute Johnson wrote:
>>> You can get as mad as you want but people are really trying to help you.

>>
>> That's not what bothers me. It's that they are often remarkably
>> unsuccessful at SUCCEEDING that bothers me, and in fairly silly ways.
>> For example, if you know, for sure, the exact answer to the question,
>> and you don't include it in your response, well, that's just plain silly!

>
> In this group people have some expectations about the posters
> of questions.


Define "people". What is it with you and Peter and pretending that your
personal opinions or expectations somehow have extra weight or authority
than, say, mine do? You are just people, same as I am, and last I
checked this is an unmoderated newsgroup. You're my equals, not my
superiors. You are certainly not imbued with any sort of official
authority to dictate some sort of "standard" set of opinions or
expectations on behalf of every single other person who may read or
write here.

So you'll excuse me if I take any pronouncements along the theme of
"people expect X", "this group thinks you should Y", "we insist that you
research stuff to depth Z", and so forth with grains of salt roughly the
size of Lake Okeechobee, mmmkay?

Really, those sorts of things should have the pronoun "I" in place of
vague (or speaking-for-everyone arrogance) references to some mysterious
"people" or "we" or suchlike.

YOU have some expectations about the posters of questions. But you
really should not presume to speak on behalf of everyone else in the
universe!

> Those begging to learn Java or learn programming should find
> groups better suited for that.


And I am not one of these. I just had one narrowly specific question
about an aspect of Swing about which I found the docs to be less than
100% clear.

If you don't like that, well, tough. Ignore my question and move on.
This is an unmoderated group; things will sometimes appear in it that
you don't like, and it behooves you to be more tolerant of such events.
You have the ability to mark something read without actually reading it.
You have resort to a killfile. Not everything one dislikes needs to be
responded to with criticism. (Though outright rudeness and bad-faith
behavior like I've seen from you and Peter sure does.)

>> you reply not with what I ask for but with your own
>> mixture of suspicions, idle questions, and sometimes outright insults.

>
> That is a typical mistake among new programmers.


No, it is a typical mistake among you and Peter and perhaps a few other
people here.

> You really don't want to


I will decide what I do or don't want to do, you arrogant little prick!

I have already explained exactly why I need to explicitly repaint my
subclassed list control sometimes. I should not have had to; I am not
under any obligation to justify my design choices to arrogant little
twerps on Usenet. However you have made it quite clear that you are not
only going to be hostile to me, but publicly deride me as a Bad
Programmer(tm), if I do NOT justify my design choices to you.

In short, you are actually EXTORTING such justifications from me by
actually THREATENING TO HARM MY REPUTATION if I DON'T do so.

Do you realize how ridiculous, arrogant, and nasty such behavior is???

Now read my lips: The people posting questions here are, by and large,
adults, capable of making their own decisions and choices, and if they
want outside advice on any particular such, they will ask for it; they
are not small children and you are not parents that need to give them
guidance lest they step on broken glass, not wear their helmets, or
what-have-you.

Let go of that paternalistic (and consequently, to adults rude,
condescending, and arrogant!) attitude and approach this as an
interaction among equals, adult human beings that are all equal before
the law (and all equal in an unmoderated newsgroup). Take questions at
face value unless there is clear evidence that someone is not acting in
good faith. Assume we're clueful and not Java newbies (even if new to
the newsgroup!) unless PROVEN otherwise, and then just ignore those
people after telling them to go to cljh.

Following the above recommendations will result in a MUCH more congenial
atmosphere around here, and as a side benefit will push the ACTUAL
clueless newbs over to the appropriate newsgroup in a more polite way
than by making them feel unwelcome here by being actively rude and
hostile to them (and, worse, to everyone you merely SUSPECT, often
wrongly, of being one).

> This is a forum where you get the best advice whether you want
> it or not.


You arrogant little jerk.

And you have paid the price for your arrogance, and that is BEING WRONG
IN PUBLIC. I have explained why I need to explicitly call repaint for my
list subclass. I have explained that there is nothing whatsoever wrong
in my design. (Indeed, it is now tested and working, and thank you very
much for the vote of frigging confidence! It also has a nice and clean
interface, surprisingly enough to you I'm sure.) You thought I really
needed to do something different from explicitly calling repaint, but
you thought wrong! And now you get to have your face rubbed in that, in
public, all because you were so arrogant, rude, and condescending.

If you'd assumed that I knew what I was doing until proven otherwise
(which, in my case, would be "never"), then perhaps you wouldn't have
stepped in it.

But it's too late now.

>> JComponent has no no-arg repaint() method save, according to another
>> post to this thread, one it inherits from java.awt.Component. Of
>> course, since I was not looking at the AWT docs, only JList and
>> JComponent, and expecting anything generally useful for Swing
>> components to be in the latter in particular, I didn't know about it
>> earlier.

>
> It is on the JComponent document page as well.


It is LINKED FROM the JComponent document page, though not anywhere
where it's very easy to find by a quick visual check for
relevant-looking method descriptions.

(Arne has some nasty rude and condescending suggestions after this
point, but I have trimmed them without dignifying them with a detailed
response. It is likely that Arne would have found my suggestions to be
anatomically impossible anyway.)

>> Perhaps I didn't make it clear enough in my previous post to this
>> thread. I have not finished the component and begun testing it yet.
>> When I do, I will of course observe normal Swing thread-safety
>> procedures and avoid doing long tasks on the EDT.

>
> I suggest you do it right the first time.


And of course I did; the main methods for my test cases look like this:

public static void main (String[] args) {
SwingUtilities.invokeAndWait(new Runnable() {
...
});
}

Not a blamed thing except for the creation of a Runnable and the calling
of a SwingUtilities method occurring on any OTHER thread than the EDT.

I DO know what I am doing, whether you choose to believe that or not.
 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      08-16-2008
Joshua Cranmer wrote:
> You're looking for a method to get a JComponent to repaint. I don't know
> about you, but I consider repainting to be a core widget action. That
> means I will look first at the root of the widget hierarchy, which is
> obviously Component (JComponent is only the root of the lightweight
> hierarchy).


You are approaching the search with a detailed knowledge of Swing
internals and design decisions. You are not approaching it from the
perspective of a user of Swing that is more concerned with doing useful
stuff with it than with knowing its in-depth implementation, history,
and so forth.

In particular, I don't think of a "widget hierarchy" and a separate
"lightweight hierarchy"; I think of AWT and Swing, and consider Swing's
borrowing of various AWT things to be code reuse and avoiding
reinventing the wheel, to the extent that I consider it at all.
JComponent is the root of the Swing component hierarchy, as far as I am
concerned (and as far as the docs and tutorial are concerned, too), and
though it inherits Component, this seems to be more of a historical
artifact than anything else.

It is unfortunate that it relies on Component to provide some of its
interface instead of overriding those methods (even with just a call to
super!) still relevant to Swing JComponents so that they appear in the
main listing of JComponent methods.

> Also, if you examine the basic structure of the AWT and Swing methods,
> you will find LARGE numbers of overloads, and especially methods that do
> fair amount of method wrapping (i.e. A is really a wrapper around B with
> a bit more magic involved).


This sort of wrapping was exactly at issue here, as I was unsure which
level of wrapping around the repaint was best just to make an unresized
component with possibly-resized internal bits repaint itself in its
entirety.

This fact, that I was not unsure how to repaint at all but how BEST to
repaint, with what level of wrapping, in a particular situation, seems
to keep getting lost in all of this needless and inexplicable acrimony.

> Looking for methods only in a leaf class is not going to be complete.


JComponent looks a lot more like a root than it does like a leaf to the
typical user of JComponent.

The problem isn't even that your perspective differs from mine. It is
that you (collective "you", referring to nearly everyone in this thread
except for me and Daniele) arrogantly presume that anyone whose
perspective differs from yours is defective, ignorant, stupid, or some
such epithet, and take paints to make your opinion clear to the general
public!

Daniele's response to my original post is the model to follow in your
future interactions with people who ask a question here. (Roedy's, a
thinly-disguised promotion of his own web site with little other
content, certainly is not -- I didn't find the stuff at his website
especially useful, anyway, except to indicate that revalidate wasn't the
way to go, and besides, I prefer direct answers to breadcrumb trails
when I have questions.)

>> Yes, there is, and his name is Peter Duniho. Cursing: "RTFM", at least
>> twice.

>
> Actually, some people interpret "RTFM" as "Read The Fine Manual", i.e.,
> look at the nuances deep in the text.


I'm not interested in your attempts to make excuses for someone who can,
if he so chooses, speak for himself, and who seems to have no excuse for
his uncouth and unpleasant public behavior anyway.

>> The sets of people that they've called rude have a fair degree of
>> overlap, too, particularly tending to include Andreas, Andrew, Arne,
>> and Lew.


And, checking the list again, you.

> Account for the fact that Andrew and Lew are in what I would consider
> the top tier of posters


Excuse me? What the heck feudal society did you log in from? Where I
live, we hold various truths to be self-evident, among them that all men
are created equal and have certain inalienable rights. (Unfortunately,
"polite and respectful treatment by others, absent prior hostile
interpersonal history" does not seem to be enumerated among the OFFICIAL
list of such rights.)

As far as I am concerned, there are no "tiers" here, with some king or
emperor or other such poobah at the top, dukes and earls on the next
level down, and lowly peasants at the bottom, with rudeness toward those
below expected and encouraged and brownnosing toward those above
demanded with a great big Or Else.

There are just people here, and some of them are more knowledgeable
about some things than others, others are more knowledgeable about some
other things than yet others, and yes, some are quite evidently more
polite, politic, circumspect, and civil than others too.

If there is to be any basis here for a class division, it should really
be the latter distinction, with the sometimes-gratuitously-rude people
considered to be low-class and subject to lesser consideration and
poorer treatment by the polite majority.

But even that is too classist for my tastes.

> For comparison, I would place myself no higher than the third tier


EVER so humble, arencha?

> Those who respond the most tend to be those who get the most mud
> flung at them.


Some people seem to get more than others. Patricia and Daniele seem
knowledgeable and astute, and seem to post a lot of answers, but I don't
notice much mud being flung at either. It looks like perhaps there is
something else that affects the amount of mud thrown at the major
question-answering personages here, besides their level of knowledge or
posting frequency. I wonder what that could be?

(It is certainly interesting that there is a correlation between female
sex and more decorum and civility. I'm guessing this is a socialized,
rather than a genetic, difference in behavior. Women are still raised to
be polite in public. Men ... aren't so much, these days, it seems. Men
also seem to be much more socialized towards a notion of behavior that
seems to be describable with "be deferent to those above you, arrogant
and uncharitable to those below you, and always know your place and put
others in theirs" and generally pecking-order oriented instead of "treat
everyone with equal respect".)

> Posters of... controversy probably get more, though
> (think XahLee, Twisted, or JSH).


Dissension should be tolerated in a free and just society. One would
hope that an unmoderated newsgroup would be a paragon of such, lacking
as it does anyone with actual authority backed by actual ability to
forcibly impose his will upon others. But oh, no ...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM
JComponent repaint nightmare Roger Davis Java 3 12-11-2003 12:31 PM



Advertisments