Results 1 to 6 of 6
Thread: Border with LestCellRenderer
- 05-25-2009, 12:15 PM #1
Member
- Join Date
- Aug 2007
- Posts
- 40
- Rep Power
- 0
Border with LestCellRenderer
How to give border with ListCellRenderer.
I tried it using following code but I failed.
Supposeis an instanceof JListJava Code:lstFindResults
PLEASE SUGGEST MEJava Code:((DefaultListCellRenderer)lstFindResults.getCellRenderer()) .setBorder(BorderFactory.createLineBorder(Color.BLACK));
- 05-25-2009, 12:25 PM #2
Can u please send me the piece of code for better understanding?
Ramya:cool:
- 05-30-2009, 08:43 AM #3
Subclass DefaultListCellRenderer, create the desired Border as a static final field and setBorder in a getListCellRendererComponent override
dbJava Code:public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setBorder(BORDER); return this; }
- 06-01-2009, 02:57 PM #4
Member
- Join Date
- Aug 2007
- Posts
- 40
- Rep Power
- 0
Thanks Derry,
Your solution is working fine.
My Problem (Related to Border of ListCellRenderer) has been solved.
But still, I want to know that why following code is not working:-
Java Code:((DefaultListCellRenderer)lstFindResults.getCellRenderer()) .setBorder(BorderFactory.createLineBorder(Color.BLACK));Last edited by Gajesh Tripathi; 06-02-2009 at 07:22 AM.
- 06-01-2009, 09:25 PM #5
If you really want to know, trace the execution of code through JList / BasicListUI / DefaultListCellRenderer and somewhere you'll find that a border is being set that removes the custom border.
The only way you can use a custom border (and many other properties) with most renderers is to set it AFTER getting the default properties with a call to the super method.
db
- 06-02-2009, 06:59 AM #6
Member
- Join Date
- Aug 2007
- Posts
- 40
- Rep Power
- 0
Similar Threads
-
[SOLVED] Changing a JButton's border
By a_elalaily in forum AWT / SwingReplies: 5Last Post: 05-11-2009, 12:07 AM -
How to remove border in JComboBox
By tiro in forum AWT / SwingReplies: 2Last Post: 03-08-2009, 05:45 PM -
Textfield border problem
By jurka in forum AWT / SwingReplies: 2Last Post: 08-31-2008, 09:15 AM -
Displaying a Button with a Border
By Java Tip in forum javax.swingReplies: 0Last Post: 06-26-2008, 07:40 PM -
Border Layout
By mark-mlt in forum Java AppletsReplies: 5Last Post: 05-12-2008, 09:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks