[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

get Arrow L&F of JCombo and Place it on a JButton

Posted on 2005-04-28
15
Medium Priority
?
492 Views
Last Modified: 2012-05-05
I want to get the L&F of the JCombo's Arrow Button and place it on my JButton. How do I do that?
0
Comment
Question by:armoghan
  • 7
  • 5
  • 3
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13887629
Why not just add an arrow icon?

<long URL removed -- Lunchy>
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13887662
Ugh sorry about that url. I'll try to get it removed. Here's the same one:

http://tinyurl.com/8nz9m
0
 
LVL 18

Author Comment

by:armoghan
ID: 13888117
ohh no no..
Actually I am using  a control which is mimicing JCombo.

It also has an Arrow button similar to JCombo's arrow button.

Now I am using this control and my JCombo on places. I want both of them to have a similar look and feel.

Now users are using different themes. Most are using XP theme..
They see two different types of combos in a Panel.

So the solution which i thought was to get the look& Feel of JCombo's arrow "Somehow" and place it on the  Mimiced JCombo's arrow Button.



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 13888159
Sorry - i've never had enough commitment to Java guis to get in as deep as LAF ;-) Someone else may be along ...
0
 
LVL 18

Author Comment

by:armoghan
ID: 13888264
Ahh
lets hope Objects, zzynx or anyone else comes for the resuce

I have tried
com.sun.java.swing.plaf.windows.WindowsIconFactory.*
but it has all teh icons but the combo and
and dont know how to get it from
com.sun.java.swing.plaf.windows.WindowsComboBoxUI.*
0
 
LVL 18

Author Comment

by:armoghan
ID: 13888380
got it with an ugly way
Extended WindowsComboBoxUI and made createArrowButton method Public

 MyWindowsComboBoxUI myWindowsComboBoxUI = new MyWindowsComboBoxUI();
 JButton b = myWindowsComboBoxUI.createArrowButton();
 b.setPreferredSize(new Dimension(16,16));


But I am open for a better way
0
 
LVL 92

Expert Comment

by:objects
ID: 13890093
0
 
LVL 18

Author Comment

by:armoghan
ID: 13892203
I have tried BasicArrowButton.. But I could not give it the L&F of Combo in different XP themes

 javax.swing.plaf.basic.BasicArrowButton bb = new javax.swing.plaf.basic.
            BasicArrowButton(javax.swing.plaf.basic.BasicArrowButton.SOUTH);
Now I can set the color, How about RollOver image and other things.
0
 
LVL 92

Expert Comment

by:objects
ID: 13892211
XP L&F uses a different class, it uses XPComboBoxButton which is a private static inner class of the Windows ComboBox L&F.

0
 
LVL 18

Author Comment

by:armoghan
ID: 13892351
Yes I have seen that and that is the way I have done. Also mentioned above

Extended com.sun.java.swing.plaf.windows.WindowsComboBoxUI and made createArrowButton method Public

 MyWindowsComboBoxUI myWindowsComboBoxUI = new MyWindowsComboBoxUI();
 JButton b = myWindowsComboBoxUI.createArrowButton();
 b.setPreferredSize(new Dimension(16,16));

But this restricts me to Windows Look and Feel. If user changes to anyother look&feel then the combo arrow may be different
0
 
LVL 92

Expert Comment

by:objects
ID: 13892376
As the combo L&F doesn't provide public access to the arrow it'll be difficult to come up with a L&F indepentant solution.
Perhaps pulling it out of the JComboBox itself might be the way to go.
0
 
LVL 18

Author Comment

by:armoghan
ID: 13892460
ohh u mean some thing like

        JComboBox aCombo = new JComboBox();
        JButton anyLFButton= (JButton)aCombo.getComponent(0);
0
 
LVL 92

Expert Comment

by:objects
ID: 13892477
yes, a bit kludgy but can't think how else you'll get L&F independance.
0
 
LVL 18

Author Comment

by:armoghan
ID: 13899876
I have tried it but unfortunately it has not worked for me.

the problem was that the other component has a Rectangle and all the drawing is done on it.
So i am unable to replace the rectangle by the button.

Is there a way I can get all the Images of this anyLFButton? I have checked its RollOverIcon and other methods but they return Null.

So do i need to resort to Robot class to get the image?
0
 
LVL 92

Accepted Solution

by:
objects earned 1500 total points
ID: 13899884
It may not necessarily be using an image. Some L&F's may handling the arrow painting in the code so there isn't a L&F indepent way to get the arrow image.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question