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


Groups > comp.lang.java.help > #2386 > unrolled thread

JScrollpane calors

Started byemf <emfril@gmail.com>
First post2012-12-25 21:52 -0500
Last post2012-12-29 15:52 -0500
Articles 8 — 3 participants

Back to article view | Back to comp.lang.java.help


Contents

  JScrollpane calors emf <emfril@gmail.com> - 2012-12-25 21:52 -0500
    Re: JScrollpane calors "John B. Matthews" <nospam@nospam.invalid> - 2012-12-25 23:34 -0500
      Re: JScrollpane calors emf <emfril@gmail.com> - 2012-12-26 03:27 -0500
        Re: JScrollpane calors "John B. Matthews" <nospam@nospam.invalid> - 2012-12-26 11:27 -0500
          Re: JScrollpane calors emf <emfril@gmail.com> - 2012-12-26 21:27 -0500
            Re: JScrollpane calors "John B. Matthews" <nospam@nospam.invalid> - 2012-12-27 09:32 -0500
    Re: JScrollpane calors Roedy Green <see_website@mindprod.com.invalid> - 2012-12-29 09:50 -0800
      Re: JScrollpane calors "John B. Matthews" <nospam@nospam.invalid> - 2012-12-29 15:52 -0500

#2386 — JScrollpane calors

Fromemf <emfril@gmail.com>
Date2012-12-25 21:52 -0500
SubjectJScrollpane calors
Message-ID<kbdofo$lr8$1@speranza.aioe.org>
I have made a JTextArea with a JScrollpane. The colors are dark, so I 
want the scroller to have a darker color then the default. I tried

scroller.setForeground(Color.GRAY);
scroller.setBackground(Color.BLUE);

but they do not have any effect. Why?

The code is:

	outputArea = new JTextArea("", 19, 37);
	outputArea.setForeground(Color.WHITE);
	outputArea.setBackground(Color.BLACK);
	outputArea.setFont(textFont);
	outputArea.setEditable(false);
	outputPanel.add(resultsArea);

	JScrollPane scroller = new JScrollPane(resultsArea,
		JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
		JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
	scroller.setForeground(Color.GRAY);
	scroller.setBackground(Color.BLUE);
	outputPanel.add(scroller);

Thanks.

Eustace

-- 
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/bd/itaintmebabe.html

[toc] | [next] | [standalone]


#2387

From"John B. Matthews" <nospam@nospam.invalid>
Date2012-12-25 23:34 -0500
Message-ID<nospam-4940A6.23342725122012@news.aioe.org>
In reply to#2386
In article <kbdofo$lr8$1@speranza.aioe.org>, emf <emfril@gmail.com> 
wrote:

> I have made a JTextArea with a JScrollpane. The colors are dark, so I 
> want the scroller to have a darker color then the default. I tried
> 
> scroller.setForeground(Color.GRAY);
> scroller.setBackground(Color.BLUE);
> 
> but they do not have any effect. Why?

The rendering is handled by the component's UI delegate, often an 
instance of a class derived from BasicScrollBarUI. You can change the 
defaults, before instantiating any GUI objects, but the chosen Look and 
Feel is free to ignore some or all settings.

UIManager.put("ScrollBar.foreground", ...);
UIManager.put("ScrollBar.background", ...);

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

[toc] | [prev] | [next] | [standalone]


#2388

Fromemf <emfril@gmail.com>
Date2012-12-26 03:27 -0500
Message-ID<kbec5g$odp$1@speranza.aioe.org>
In reply to#2387
On 2012-12-25 23:34 John B. Matthews wrote:
> In article <kbdofo$lr8$1@speranza.aioe.org>, emf <emfril@gmail.com>
> wrote:
>
>> I have made a JTextArea with a JScrollpane. The colors are dark, so I
>> want the scroller to have a darker color then the default. I tried
>>
>> scroller.setForeground(Color.GRAY);
>> scroller.setBackground(Color.BLUE);
>>
>> but they do not have any effect. Why?
>
> The rendering is handled by the component's UI delegate, often an
> instance of a class derived from BasicScrollBarUI. You can change the
> defaults, before instantiating any GUI objects, but the chosen Look and
> Feel is free to ignore some or all settings.
>
> UIManager.put("ScrollBar.foreground", ...);
> UIManager.put("ScrollBar.background", ...);

I deleted the scroller.setForeground(...) and 
scroller.setBackground(...) statements, since they did not have any 
effect, and added your statements before

JScrollPane scroller = new JScrollPane(...

Well, they were partially effective, I mean the second was effective, 
the background did change to the color I specified, but the foreground, 
that is the scroller itself, did not change from what it was before.

Why?

1/2 Thanks,

Eustace

-- 
Date Calculator with all-purpose JS code
https://files.nyu.edu/emf202/public/js/dateCalculator.html

[toc] | [prev] | [next] | [standalone]


#2395

From"John B. Matthews" <nospam@nospam.invalid>
Date2012-12-26 11:27 -0500
Message-ID<nospam-E7F2D0.11274926122012@news.aioe.org>
In reply to#2388
In article <kbec5g$odp$1@speranza.aioe.org>, emf <emfril@gmail.com> 
wrote:

> On 2012-12-25 23:34 John B. Matthews wrote:
> > In article <kbdofo$lr8$1@speranza.aioe.org>, emf <emfril@gmail.com>
> > wrote:
[...]
> > You can change the defaults, before instantiating any GUI objects, 
> > but the chosen Look and Feel is free to ignore some or all 
> > settings.
> >
> > UIManager.put("ScrollBar.foreground", ...);
> > UIManager.put("ScrollBar.background", ...);
[...]
> Well, they were partially effective, I mean the second was effective, 
> the background did change to the color I specified, but the 
> foreground, that is the scroller itself, did not change from what it 
> was before.
> 
> Why?
[...]

You'd have to examine the particular implementation to see how it uses 
the foreground color. I generally try to avoid distorting the L&F 
design. Of course, you can always override the relevant paint method(s) 
in a custom BasicScrollBarUI.

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

[toc] | [prev] | [next] | [standalone]


#2397

Fromemf <emfril@gmail.com>
Date2012-12-26 21:27 -0500
Message-ID<kbgbdf$9m2$1@speranza.aioe.org>
In reply to#2395
On 2012-12-26 11:27 John B. Matthews wrote:
> In article <kbec5g$odp$1@speranza.aioe.org>, emf <emfril@gmail.com>
> wrote:
>
>> On 2012-12-25 23:34 John B. Matthews wrote:
>>> In article <kbdofo$lr8$1@speranza.aioe.org>, emf <emfril@gmail.com>
>>> wrote:
> [...]
>>> You can change the defaults, before instantiating any GUI objects,
>>> but the chosen Look and Feel is free to ignore some or all
>>> settings.
>>>
>>> UIManager.put("ScrollBar.foreground", ...);
>>> UIManager.put("ScrollBar.background", ...);
> [...]
>> Well, they were partially effective, I mean the second was effective,
>> the background did change to the color I specified, but the
>> foreground, that is the scroller itself, did not change from what it
>> was before.
>>
>> Why?
> [...]
>
> You'd have to examine the particular implementation to see how it uses
> the foreground color. I generally try to avoid distorting the L&F
> design. Of course, you can always override the relevant paint method(s)
> in a custom BasicScrollBarUI.

Sorry, I need more specific directions than this. But I googled the 
issue and find that this should be a solution:

public TextPaneRenderer() {
      setEditable(false);
      putClientProperty(HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
}

(https://forums.oracle.com/forums/thread.jspa?threadID=2269764)

But where do I put it?

emf

-- 
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/bd/itaintmebabe.html

[toc] | [prev] | [next] | [standalone]


#2398

From"John B. Matthews" <nospam@nospam.invalid>
Date2012-12-27 09:32 -0500
Message-ID<nospam-F824DA.09320627122012@news.aioe.org>
In reply to#2397
In article <kbgbdf$9m2$1@speranza.aioe.org>, emf <emfril@gmail.com> 
wrote:

> On 2012-12-26 11:27 John B. Matthews wrote:
> > In article <kbec5g$odp$1@speranza.aioe.org>, emf <emfril@gmail.com>
> > wrote:
> >
> >> On 2012-12-25 23:34 John B. Matthews wrote:
> >>> In article <kbdofo$lr8$1@speranza.aioe.org>, emf <emfril@gmail.com>
> >>> wrote:
> > [...]
> >>> You can change the defaults, before instantiating any GUI objects,
> >>> but the chosen Look and Feel is free to ignore some or all
> >>> settings.
> >>>
> >>> UIManager.put("ScrollBar.foreground", ...);
> >>> UIManager.put("ScrollBar.background", ...);
> > [...]
> >> Well, they were partially effective, I mean the second was effective,
> >> the background did change to the color I specified, but the
> >> foreground, that is the scroller itself, did not change from what it
> >> was before.
> >>
> >> Why?
> > [...]
> >
> > You'd have to examine the particular implementation to see how it uses
> > the foreground color. I generally try to avoid distorting the L&F
> > design. Of course, you can always override the relevant paint method(s)
> > in a custom BasicScrollBarUI.
> 
> Sorry, I need more specific directions than this. But I googled the 
> issue and find that this should be a solution:
> 
> public TextPaneRenderer() {
>       setEditable(false);
>       putClientProperty(HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
> }
> 
> (https://forums.oracle.com/forums/thread.jspa?threadID=2269764)
> 
> But where do I put it?

HONOR_DISPLAY_PROPERTIES is documented for JTextPane, but I'm not aware 
of any such client property for JScrollBar.

Just to get the flavor of it, here's a custom SliderUI:

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

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

[toc] | [prev] | [next] | [standalone]


#2399

FromRoedy Green <see_website@mindprod.com.invalid>
Date2012-12-29 09:50 -0800
Message-ID<a7bud81avtisiaqs9nl2nb3cjjutd90g3s@4ax.com>
In reply to#2386
On Tue, 25 Dec 2012 21:52:04 -0500, emf <emfril@gmail.com> wrote,
quoted or indirectly quoted someone who said :

>I have made a JTextArea with a JScrollpane. The colors are dark, so I 
>want the scroller to have a darker color then the default. I tried

have a look at the source code for JScrollPane to see where it gets
the colours. I had a similar problem with JSpinner. It turned out the
trick was to set the colours of the component pieces of a JSpinner.

You might just look for a pre-done L&F that does things the way you
want.  See http://mindprod.com/jgloss/laf.html
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Students who hire or con others to do their homework are as foolish 
as couch potatoes who hire others to go to the gym for them. 

[toc] | [prev] | [next] | [standalone]


#2400

From"John B. Matthews" <nospam@nospam.invalid>
Date2012-12-29 15:52 -0500
Message-ID<nospam-F944BB.15524729122012@news.aioe.org>
In reply to#2399
In article <a7bud81avtisiaqs9nl2nb3cjjutd90g3s@4ax.com>,
 Roedy Green <see_website@mindprod.com.invalid> wrote:

> On Tue, 25 Dec 2012 21:52:04 -0500, emf <emfril@gmail.com> wrote,
> quoted or indirectly quoted someone who said :
> 
> >I have made a JTextArea with a JScrollpane. The colors are dark, so 
> >I want the scroller to have a darker color then the default. I tried
> 
> have a look at the source code for JScrollPane to see where it gets 
> the colours.

I think the OP wants to modify the JScrollBar, rather than JTextPane, 
but no colors will be found in either component's source code. The UI 
delegate initializes default values by asking the UIManager.

> I had a similar problem with JSpinner. It turned out the 
> trick was to set the colours of the component pieces of a JSpinner.

This works for JSpinner, as it's a composite that includes other 
components. Of course, the delegate may use platform-specific 
variations, so the practice is fragile.

> You might just look for a pre-done L&F that does things the way you 
> want.  See http://mindprod.com/jgloss/laf.html

This has the salutary advantage of leveraging the designer's knowledge.

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.help


csiph-web