Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox with horizontall scroll bar

 
jack morton
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I created this custom ComboBox:

When i add this ComboBox to a Frame, it has a look and feel diffrent from the others componet
How to resolve that
Regards
Jackm
 
Brian Cole
Author
Ranch Hand
Posts: 906
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jack morton wrote:I created this custom ComboBox:

When i add this ComboBox to a Frame, it has a look and feel diffrent from the others componet
How to resolve that


If you know what L&F will be used, you can override the specific ComboBoxUI for that L&F (though it may have a structure that differs from BasicComboBoxUI, which can make it difficult). Of course it's typical to expect your code to be run under a variety of L&Fs.

This is a general problem with Swing. For this reason you don't really want to override UIs to change functionality, though sometimes there's no other way. I just spent a few minutes looking for some example code I saw somewhere that uses crazy reflection techniques to (effectively) override a method in a dynamic UI delegate, but I couldn't find it. The technique probably wouldn't have worked for your situation anyway.

[edit: spell delegate correctly]
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5369365
 
Carlos Hoces
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jack morton wrote:Hi all,
I created this custom ComboBox:
[code]import com.sun.java.swing.*;
import com.sun.java.swing.plaf.basic.*;

public class myCombo extends JComboBox{
public myCombo(){
super();
setUI(new myComboUI());
}
Jackm


In case you extend your class, like:

public class HComboBox extends myCombo{

public HComboBox(){
this.updateUI();
...
}

will set the current LaF during the execution of your class constructor.
This is how I use it, and it works well with Substance LaF, ie.
I guess if you do the same with your class, as is, it'll work equally well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic