• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

JList with EmptyBorder inside JScrollPane moves against my will

 
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been looking for a reason for this to no avail. I have a JList with an EmptyBorder (for some margin). It is in a JScrollPane. When there is a list entry that is wider than the viewport, I can click on the JList and if I move the mouse cursor any when clicking, the JList scrolls to the left, the width of the border, putting the text up next to the edge of the viewport again. This is rather annoying as it defeats the purpose of using the EmptyBorder for margin.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post an SSCCE.
 
Mack Wilmot
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although I am using the free design in NetBeans, I generated the simplest case with a null layout and it behaves the same. This is the Windows L&F, but it does the same with Metal, Nimbus L&F.

 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. I see where that behavior is coming from. Take a look at line 2761 of BasicListUI.java, in the handler's mouseDragged(...) method.

One way to get the behavior you desire is to use a custom renderer and set the left/right borders to the renderer, and the top/bottom borders to the JList.You'll need to test whether that works with all LaFs.
 
Mack Wilmot
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Darryl!
 
Mack Wilmot
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works on all the available L&F in NetBeans. I just added it to the form through the custom code properties, pre-adding for the JLabel (Lines 28-45), although I could add it in my controller. I see how it adds the border to the cell and no matter if I add it before or after adding a border to the JList, the code takes that into account. But in my case I don't need the border on the JList. Thanks again.
 
Darryl Burke
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mack Wilmot wrote:It works on all the available L&F in NetBeans.


Thank you for testing and reporting back.
 
Mack Wilmot
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The check for a null border is not needed in my case. What it does is still detects a border, it is never null, even though I do not add one it still creates a compound border. This over pads the cell plus it causes a very thin dotted line to show around a cell when it is selected. So all I need is this code:




 
reply
    Bookmark Topic Watch Topic
  • New Topic