Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38302
| Path | csiph.com!news.redatomik.org!aioe.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How does a scrollbar paint differently? |
| Date | Wed, 30 May 2018 20:35:35 +0200 |
| Organization | A noiseless patient Spider |
| Lines | 91 |
| Message-ID | <pemqvr$l43$1@dont-email.me> (permalink) |
| References | <00f505eb-cb45-4306-a554-bfad87371dd9@googlegroups.com> <7f435fa4-c7c0-4899-a757-f900eaae07f8@googlegroups.com> <pekg11$r62$1@dont-email.me> <21dc0f98-f0b2-44fd-967c-e98563fcbb15@googlegroups.com> <194b2ea5-122d-49f6-b284-9f80fcb2ab62@googlegroups.com> <e7be5767-600c-4bc2-af42-93cd681d6abe@googlegroups.com> <pemimn$q30$1@dont-email.me> <afe8fb1f-6821-4abf-81fd-9c903f6fe4a0@googlegroups.com> <6fee2a82-bcd7-4cdc-8ee2-183109738808@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 30 May 2018 18:36:43 -0000 (UTC) |
| Injection-Info | h2725194.stratoserver.net; posting-host="714a70d6cef6e106e01faf371a84ca5f"; logging-data="21635"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/s6/m5KjpHbEKnQQ9EjyxM" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 |
| Cancel-Lock | sha1:4AQr/BmEwNbRwZSGk8k3kkKDZEE= |
| In-Reply-To | <6fee2a82-bcd7-4cdc-8ee2-183109738808@googlegroups.com> |
| X-Antivirus-Status | Clean |
| Content-Language | en-GB |
| X-Antivirus | AVG (VPS 180530-0, 05/30/2018), Outbound message |
| Xref | csiph.com comp.lang.java.programmer:38302 |
Show key headers only | View raw
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.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web