Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38290 > unrolled thread
| Started by | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| First post | 2018-05-29 12:42 -0700 |
| Last post | 2018-05-30 20:35 +0200 |
| Articles | 12 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-29 12:42 -0700
Re: How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-29 13:50 -0700
Re: How does a scrollbar paint differently? Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-05-29 17:17 -0400
Re: How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-30 07:37 -0700
Re: How does a scrollbar paint differently? Eric Sosman <esosman@comcast-dot-net.invalid> - 2018-05-30 11:09 -0400
Re: How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-30 08:26 -0700
Re: How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-30 08:24 -0700
Re: How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-30 08:46 -0700
Re: How does a scrollbar paint differently? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-05-30 18:14 +0200
Re: How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-30 10:31 -0700
Re: How does a scrollbar paint differently? Eric Douglas <e.d.programmer@gmail.com> - 2018-05-30 10:53 -0700
Re: How does a scrollbar paint differently? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2018-05-30 20:35 +0200
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-29 12:42 -0700 |
| Subject | How does a scrollbar paint differently? |
| Message-ID | <00f505eb-cb45-4306-a554-bfad87371dd9@googlegroups.com> |
I put a JTextArea in a JScrollPane. If I load this control in a JFrame from Eclipse it displays a scrollbar with solid triangles and a grey bar with 3 lines in the middle. If I put this same control in my application, where a 3rd party API is handling the window, the scrollbar has a single chevron on the ends and an undecorated bar that's a different shade of gray, which matches the bar in my C# application. Both Java systems return a com.sun.java.swing.plaf.windows.WindowsLookAndFeel from the UIManager.getLookAndFeel().
[toc] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-29 13:50 -0700 |
| Message-ID | <7f435fa4-c7c0-4899-a757-f900eaae07f8@googlegroups.com> |
| In reply to | #38290 |
On Tuesday, May 29, 2018 at 3:42:49 PM UTC-4, Eric Douglas wrote: > I put a JTextArea in a JScrollPane. If I load this control in a JFrame from Eclipse it displays a scrollbar with solid triangles and a grey bar with 3 lines in the middle. If I put this same control in my application, where a 3rd party API is handling the window, the scrollbar has a single chevron on the ends and an undecorated bar that's a different shade of gray, which matches the bar in my C# application. Both Java systems return a com.sun.java.swing.plaf.windows.WindowsLookAndFeel from the UIManager.getLookAndFeel(). Correction, JList control, not JTextArea, though probably irrelevant.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2018-05-29 17:17 -0400 |
| Message-ID | <pekg11$r62$1@dont-email.me> |
| In reply to | #38291 |
On 5/29/2018 4:50 PM, Eric Douglas wrote:
> On Tuesday, May 29, 2018 at 3:42:49 PM UTC-4, Eric Douglas wrote:
>> I put a JTextArea in a JScrollPane. If I load this control in a JFrame from Eclipse it displays a scrollbar with solid triangles and a grey bar with 3 lines in the middle. If I put this same control in my application, where a 3rd party API is handling the window, the scrollbar has a single chevron on the ends and an undecorated bar that's a different shade of gray, which matches the bar in my C# application. Both Java systems return a com.sun.java.swing.plaf.windows.WindowsLookAndFeel from the UIManager.getLookAndFeel().
>
> Correction, JList control, not JTextArea, though probably irrelevant.
The first scrollbar sounds like the one belonging to the Java cross-
platform "Metal" look and feel, javax.swing.plaf.metal.MetalLookAndFeel.
The other sounds like com.sun.java.swing.plaf.windows.WindowsLookAndFeel
(or possibly com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel).
Are you *sure* both getLookAndFeel() calls return the latter? Or, are
you *sure* that there's no setLookAndFeel() call after getLookAndFeel()?
--
esosman@comcast-dot-net.invalid
Nine hundred sixty-seven days to go.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-30 07:37 -0700 |
| Message-ID | <21dc0f98-f0b2-44fd-967c-e98563fcbb15@googlegroups.com> |
| In reply to | #38292 |
On Tuesday, May 29, 2018 at 5:17:35 PM UTC-4, Eric Sosman wrote: > The first scrollbar sounds like the one belonging to the Java cross- > platform "Metal" look and feel, javax.swing.plaf.metal.MetalLookAndFeel. > The other sounds like com.sun.java.swing.plaf.windows.WindowsLookAndFeel > (or possibly com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel). > Are you *sure* both getLookAndFeel() calls return the latter? Or, are > you *sure* that there's no setLookAndFeel() call after getLookAndFeel()? > I definitely only call setLookAndFeel once, where I am assigning the WindowsLookAndFeel. I just tried creating a raw test program with all Oracle classes, and javax.swing.plaf.metal.MetalLookAndFeel is the default LookAndFeel, and when I assign the WindowsLookAndFeel it looks right. So now I have to see what my custom classes are doing differently that I was definitely calling the set for the WindowsLookAndFeel but somehow it displayed the scrollbar as MetalLookAndFeel.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2018-05-30 11:09 -0400 |
| Message-ID | <pemequ$vej$1@dont-email.me> |
| In reply to | #38294 |
On 5/30/2018 10:37 AM, Eric Douglas wrote:
> On Tuesday, May 29, 2018 at 5:17:35 PM UTC-4, Eric Sosman wrote:
>> The first scrollbar sounds like the one belonging to the Java cross-
>> platform "Metal" look and feel, javax.swing.plaf.metal.MetalLookAndFeel.
>> The other sounds like com.sun.java.swing.plaf.windows.WindowsLookAndFeel
>> (or possibly com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel).
>> Are you *sure* both getLookAndFeel() calls return the latter? Or, are
>> you *sure* that there's no setLookAndFeel() call after getLookAndFeel()?
>>
>
> I definitely only call setLookAndFeel once, where I am assigning the WindowsLookAndFeel. I just tried creating a raw test program with all Oracle classes, and javax.swing.plaf.metal.MetalLookAndFeel is the default LookAndFeel, and when I assign the WindowsLookAndFeel it looks right. So now I have to see what my custom classes are doing differently that I was definitely calling the set for the WindowsLookAndFeel but somehow it displayed the scrollbar as MetalLookAndFeel.
>
Your original post mentioned that "a 3rd party API is handling the
window," and perhaps that's where some look-and-feel shenanigans occur.
I don't know whether you can change (or even inspect) the internals of
the third-party code, but perhaps you could get a few clues by calling
UIManager.getLookAndFeel() more than once -- like, say, before building
any of your UI, and again after the UI appears on-screen.
--
esosman@comcast-dot-net.invalid
Nine hundred sixty-six days to go.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-30 08:26 -0700 |
| Message-ID | <675de10c-bf82-4893-9051-8b47320487b7@googlegroups.com> |
| In reply to | #38295 |
On Wednesday, May 30, 2018 at 11:09:29 AM UTC-4, Eric Sosman wrote: > Your original post mentioned that "a 3rd party API is handling the > window," and perhaps that's where some look-and-feel shenanigans occur. > I don't know whether you can change (or even inspect) the internals of > the third-party code, but perhaps you could get a few clues by calling > UIManager.getLookAndFeel() more than once -- like, say, before building > any of your UI, and again after the UI appears on-screen. > No the 3rd party API handling the window displaying the JList/JScrollPane from my custom class is displaying the right scrollbar. It was my Eclipse test frame displaying the wrong one.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-30 08:24 -0700 |
| Message-ID | <194b2ea5-122d-49f6-b284-9f80fcb2ab62@googlegroups.com> |
| In reply to | #38294 |
On Wednesday, May 30, 2018 at 10:38:07 AM UTC-4, Eric Douglas wrote: > On Tuesday, May 29, 2018 at 5:17:35 PM UTC-4, Eric Sosman wrote: > > The first scrollbar sounds like the one belonging to the Java cross- > > platform "Metal" look and feel, javax.swing.plaf.metal.MetalLookAndFeel. > > The other sounds like com.sun.java.swing.plaf.windows.WindowsLookAndFeel > > (or possibly com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel). > > Are you *sure* both getLookAndFeel() calls return the latter? Or, are > > you *sure* that there's no setLookAndFeel() call after getLookAndFeel()? > > > > I definitely only call setLookAndFeel once, where I am assigning the WindowsLookAndFeel. I just tried creating a raw test program with all Oracle classes, and javax.swing.plaf.metal.MetalLookAndFeel is the default LookAndFeel, and when I assign the WindowsLookAndFeel it looks right. So now I have to see what my custom classes are doing differently that I was definitely calling the set for the WindowsLookAndFeel but somehow it displayed the scrollbar as MetalLookAndFeel. I fixed it. ... My test class has a display method which creates the JFrame, adds the JList, and sets it visible. This method gets called from the EventQueue.invokeLater. I had multiple methods which needed to reference the JList/JScrollPane control so I made that a class level variable, but I also called the constructor for that up where I declared it, so it was deciding which scrollbars to display before I set the LookAndFeel. If I add a setLookAndFeel in that class in a static block, or move the constructor call into the method after the setLookAndFeel it works fine. Now how to change the scrollbars? If I call the constructor for the JScrollPane, then call UIManager.setLookAndFeel, then call the JScrollPane's updateUI(), it's still showing the default bars.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-30 08:46 -0700 |
| Message-ID | <e7be5767-600c-4bc2-af42-93cd681d6abe@googlegroups.com> |
| In reply to | #38296 |
On Wednesday, May 30, 2018 at 11:24:28 AM UTC-4, Eric Douglas wrote: > Now how to change the scrollbars? If I call the constructor for the JScrollPane, then call UIManager.setLookAndFeel, then call the JScrollPane's updateUI(), it's still showing the default bars. So apparently the parent is irrelevant. I can't change/update the LookAndFeel on the JScrollPane. If I want the scrollbars to change appearance after changing the LookAndFeel I have to specifically get the scrollbars either from the getComponents() or their specific as getVerticalScrollBar(), then call the updateUI() on the bar(s) themselves (or call SwingUtilities.updateComponentTreeUI which cascades down to them).
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2018-05-30 18:14 +0200 |
| Message-ID | <pemimn$q30$1@dont-email.me> |
| In reply to | #38298 |
On 2018-05-30 17:46, Eric Douglas wrote: > On Wednesday, May 30, 2018 at 11:24:28 AM UTC-4, Eric Douglas wrote: >> Now how to change the scrollbars? If I call the constructor for the JScrollPane, then call UIManager.setLookAndFeel, then call the JScrollPane's updateUI(), it's still showing the default bars. > > So apparently the parent is irrelevant. I can't change/update the LookAndFeel on the JScrollPane. If I want the scrollbars to change appearance after changing the LookAndFeel I have to specifically get the scrollbars either from the getComponents() or their specific as getVerticalScrollBar(), then call the updateUI() on the bar(s) themselves (or call SwingUtilities.updateComponentTreeUI which cascades down to them). Dude, no one here has any idea what you're talking about. There's a reason code gets written in programming languages, not English. What's your angle? Soliloquy? -- DF.
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-30 10:31 -0700 |
| Message-ID | <afe8fb1f-6821-4abf-81fd-9c903f6fe4a0@googlegroups.com> |
| In reply to | #38299 |
On Wednesday, May 30, 2018 at 12:15:30 PM UTC-4, Daniele Futtorovic wrote:
> On 2018-05-30 17:46, Eric Douglas wrote:
> > On Wednesday, May 30, 2018 at 11:24:28 AM UTC-4, Eric Douglas wrote:
> >> Now how to change the scrollbars? If I call the constructor for the JScrollPane, then call UIManager.setLookAndFeel, then call the JScrollPane's updateUI(), it's still showing the default bars.
> >
> > So apparently the parent is irrelevant. I can't change/update the LookAndFeel on the JScrollPane. If I want the scrollbars to change appearance after changing the LookAndFeel I have to specifically get the scrollbars either from the getComponents() or their specific as getVerticalScrollBar(), then call the updateUI() on the bar(s) themselves (or call SwingUtilities.updateComponentTreeUI which cascades down to them).
>
>
> Dude, no one here has any idea what you're talking about. There's a
> reason code gets written in programming languages, not English. What's
> your angle? Soliloquy?
>
> --
> DF.
Basically, my test class was doing this (with the setLookAndFeel in a custom class which extends JFrame).
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class TestListScroll {
private DefaultListModel<String> jlm = new DefaultListModel<>();
private JList<?> jl = new JList<>(jlm);
private JScrollPane sp = new JScrollPane(jl);
public TestListScroll() {
final JFrame f = new JFrame();
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setPreferredSize(new Dimension(180, 120));
sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
f.getContentPane().add(sp);
jl.setFixedCellHeight(15);
jlm.addElement("one");
jlm.addElement("two");
jlm.addElement("three");
jlm.addElement("four");
jlm.addElement("five");
jlm.addElement("six");
jlm.addElement("seven");
f.setLocationRelativeTo(null);
f.pack();
f.setVisible(true);
}
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new TestListScroll();
}
});
}
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2018-05-30 10:53 -0700 |
| Message-ID | <6fee2a82-bcd7-4cdc-8ee2-183109738808@googlegroups.com> |
| In reply to | #38300 |
On Wednesday, May 30, 2018 at 1:32:05 PM UTC-4, Eric Douglas wrote:
> On Wednesday, May 30, 2018 at 12:15:30 PM UTC-4, Daniele Futtorovic wrote:
> Basically, my test class was doing this (with the setLookAndFeel in a custom class which extends JFrame).
>
> import java.awt.Dimension;
> import java.awt.EventQueue;
>
> import javax.swing.DefaultListModel;
> import javax.swing.JFrame;
> import javax.swing.JList;
> import javax.swing.JScrollPane;
> import javax.swing.ScrollPaneConstants;
> import javax.swing.UIManager;
> import javax.swing.UnsupportedLookAndFeelException;
>
> public class TestListScroll {
>
> private DefaultListModel<String> jlm = new DefaultListModel<>();
> private JList<?> jl = new JList<>(jlm);
> private JScrollPane sp = new JScrollPane(jl);
>
> public TestListScroll() {
> final JFrame f = new JFrame();
> try {
> UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
> } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
> e.printStackTrace();
> }
> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> f.setPreferredSize(new Dimension(180, 120));
> sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
> sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
> f.getContentPane().add(sp);
> jl.setFixedCellHeight(15);
> jlm.addElement("one");
> jlm.addElement("two");
> jlm.addElement("three");
> jlm.addElement("four");
> jlm.addElement("five");
> jlm.addElement("six");
> jlm.addElement("seven");
> f.setLocationRelativeTo(null);
> f.pack();
> f.setVisible(true);
> }
>
> public static void main(final String[] args) {
>
> EventQueue.invokeLater(new Runnable() {
>
> @Override
> public void run() {
> new TestListScroll();
> }
> });
> }
So I figured out I need to setLookAndFeel up front:
public class TestListScroll {
{
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
private DefaultListModel<String> jlm = new DefaultListModel<>();
private JList<?> jl = new JList<>(jlm);
private JScrollPane sp = new JScrollPane(jl);
public TestListScroll() {
final JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
...
or after the fact.
...
f.pack();
SwingUtilities.updateComponentTreeUI(f);
f.setVisible(true);
}
You can't just assign it to a JScrollBar after the JScrollPane is created by just calling UIManager.setLookAndFeel, or by calling .updateUI() on the JScrollPane. You have to call the setLookAndFeel before the JScrollPane is created, or get the scrollbar(s) from the JScrollPane and call their updateUI() method. I was missing this in my test, took me awhile to realize.
[toc] | [prev] | [next] | [standalone]
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
|---|---|
| Date | 2018-05-30 20:35 +0200 |
| Message-ID | <pemqvr$l43$1@dont-email.me> |
| In reply to | #38301 |
On 2018-05-30 19:53, Eric Douglas wrote:
> On Wednesday, May 30, 2018 at 1:32:05 PM UTC-4, Eric Douglas wrote:
>> On Wednesday, May 30, 2018 at 12:15:30 PM UTC-4, Daniele Futtorovic wrote:
>> Basically, my test class was doing this (with the setLookAndFeel in a custom class which extends JFrame).
>>
>> import java.awt.Dimension;
>> import java.awt.EventQueue;
>>
>> import javax.swing.DefaultListModel;
>> import javax.swing.JFrame;
>> import javax.swing.JList;
>> import javax.swing.JScrollPane;
>> import javax.swing.ScrollPaneConstants;
>> import javax.swing.UIManager;
>> import javax.swing.UnsupportedLookAndFeelException;
>>
>> public class TestListScroll {
>>
>> private DefaultListModel<String> jlm = new DefaultListModel<>();
>> private JList<?> jl = new JList<>(jlm);
>> private JScrollPane sp = new JScrollPane(jl);
>>
>> public TestListScroll() {
>> final JFrame f = new JFrame();
>> try {
>> UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
>> } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
>> e.printStackTrace();
>> }
>> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>> f.setPreferredSize(new Dimension(180, 120));
>> sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
>> sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
>> f.getContentPane().add(sp);
>> jl.setFixedCellHeight(15);
>> jlm.addElement("one");
>> jlm.addElement("two");
>> jlm.addElement("three");
>> jlm.addElement("four");
>> jlm.addElement("five");
>> jlm.addElement("six");
>> jlm.addElement("seven");
>> f.setLocationRelativeTo(null);
>> f.pack();
>> f.setVisible(true);
>> }
>>
>> public static void main(final String[] args) {
>>
>> EventQueue.invokeLater(new Runnable() {
>>
>> @Override
>> public void run() {
>> new TestListScroll();
>> }
>> });
>> }
>
> So I figured out I need to setLookAndFeel up front:
>
> public class TestListScroll {
> {
> try {
> UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
> } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
> e.printStackTrace();
> }
> }
>
> private DefaultListModel<String> jlm = new DefaultListModel<>();
> private JList<?> jl = new JList<>(jlm);
> private JScrollPane sp = new JScrollPane(jl);
>
> public TestListScroll() {
> final JFrame f = new JFrame();
> f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> ...
>
> or after the fact.
> ...
> f.pack();
> SwingUtilities.updateComponentTreeUI(f);
> f.setVisible(true);
> }
>
> You can't just assign it to a JScrollBar after the JScrollPane is created by just calling UIManager.setLookAndFeel, or by calling .updateUI() on the JScrollPane. You have to call the setLookAndFeel before the JScrollPane is created, or get the scrollbar(s) from the JScrollPane and call their updateUI() method. I was missing this in my test, took me awhile to realize.
Thank you. That makes a lot more sense.
--
DF.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web