Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #5190

Re: Overriding JComponent or implementing ComponentUI?

From "John B. Matthews" <nospam@nospam.invalid>
Newsgroups comp.lang.java.gui
Subject Re: Overriding JComponent or implementing ComponentUI?
Date 2012-07-05 21:06 -0400
Organization The Wasteland
Message-ID <nospam-74D9F0.21064205072012@news.aioe.org> (permalink)
References <kN1Ir.59786$GJ4.56436@newsfe16.iad> <Swing-color-names-20120703132124@ram.dialup.fu-berlin.de>

Show all headers | View raw


In article <Swing-color-names-20120703132124@ram.dialup.fu-berlin.de>,
 ram@zedat.fu-berlin.de (Stefan Ram) wrote:

> Daniel Pitts <newsgroup.nospam@virtualinfinity.net> writes:
> >Does anyone have any experience with implementing ComponentUI classes? 
> >It seems to be part of the PLAF architecture, and since this isn't 
> >really a look-and-feel configurable component, it seems like that may be 
> >overkill.
> 
>   To address one detail: When doing custom painting, the
>   component should fit into the LAF appearance. So, for
>   example, when painting the thumb of a custom scrollbar,
>   one would use the color obtained as follows:
> 
> final java.awt.Color thumbColor = 
> javax.swing.UIManager.getColor( "ScrollBar.thumb" );
> 
>   . Why does nobody use »getColor«?
> 
>   It might be related to the fact that these color names, such
>   as »ScrollBar.thumb« are not defined statically. So one can
>   never be sure whether the current environment »supports« a
>   given color name. This seems to render them useless for
>   using them in source code.
> 
>   What should be done is to define a subset of color names
>   statically (such as »Foreground« and »Background«) that
>   is guaranteed to always be available.

Daniel: Stefan Ram' point is well taken. You may be able to find a 
subset of named defaults in the intersection of L&Fs you plan to 
support. To ensure that your component can respond to a dynamic change 
in L&F, (re-) apply your changes in updateUI(), as shown in this example 
that conditions a JToggleButton to resemble a JTable header:

<http://stackoverflow.com/a/7137801/230513>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Overriding JComponent or implementing ComponentUI? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-07-01 12:45 -0700
  Re: Overriding JComponent or implementing ComponentUI? "John B. Matthews" <nospam@nospam.invalid> - 2012-07-01 20:11 -0400
  Re: Overriding JComponent or implementing ComponentUI? Roedy Green <see_website@mindprod.com.invalid> - 2012-07-05 07:40 -0700
    Re: Overriding JComponent or implementing ComponentUI? "John B. Matthews" <nospam@nospam.invalid> - 2012-07-05 21:11 -0400
  Re: Overriding JComponent or implementing ComponentUI? "John B. Matthews" <nospam@nospam.invalid> - 2012-07-05 21:06 -0400
  Re: Overriding JComponent or implementing ComponentUI? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-10 01:42 +0200
    Re: Overriding JComponent or implementing ComponentUI? Lew <noone@lewscanon.com> - 2012-07-09 23:30 -0700
      Re: Overriding JComponent or implementing ComponentUI? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-10 20:18 +0200
        Re: Overriding JComponent or implementing ComponentUI? Lew <lewbloch@gmail.com> - 2012-07-10 13:25 -0700

csiph-web