This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create pull-down button

 
Lang Miao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do any of you know how to make this sort of button (attached below)? It's a button with an arrow next to it, which, when clicked on, offers other options. And I don't use GUI builder, so just don't tell me to drag and drop the appropriate control.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like a comboBox, contents being a label with icon and text
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks more like a JMenu thats part of a ToolBar or MenuBar.

check out:
http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html


-Tad
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I don't use GUI builder, so just don't tell me to drag and drop the appropriate control.

First I'd work on being a little bit friendlier. I haven't noticed anyone here at Javaranch telling you to do such a thing in your 8 post. We are all pretty nice helpful folk when people are nice to us. Demanding things will get you nowhere. You'll soon learn how nice we are compared to those other forums where people tell you to do such silly things. Real programmers don't use GUI builders anyway.

As to your question, this is a control that you would have to make yourself or find someone who has made such a custom component. Obviously SWT/JFace might have some sort of control like this since you are showing us an Eclipse screenshot.

My suggestion would be to do something like this:

Create 2 borderless buttons on a single JPanel with no space between them.
Have one of the buttons be the down arrow and when it is clicked popup a JPopupMenu below the button. Technically that's all a JComboBox is. A textfield and a button that displays a JPopupMenu. You would do the same thing minus the textfield.

Hope that helps.
 
Lang Miao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gregg Bolinger:
And I don't use GUI builder, so just don't tell me to drag and drop the appropriate control.

First I'd work on being a little bit friendlier. I haven't noticed anyone here at Javaranch telling you to do such a thing in your 8 post. We are all pretty nice helpful folk when people are nice to us. Demanding things will get you nowhere. You'll soon learn how nice we are compared to those other forums where people tell you to do such silly things. Real programmers don't use GUI builders anyway.



Dude,seriously I didn't mean to be unfriendly with my above statement. I just wanted to say beforehand that some solution will not be applicable to me.

Anyhow, thanks for your reply. It confirms that there's no one Swing component that does all that type of button.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lang, I misread your post so sorry for coming off the way I did. We have a lot of people coming in here and demanding help, demanding code, etc. Some people just don't realize we are all here trying to help each other learn Java.

No hard feelings I hope.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lang, it's all in the wording. Since this is a written-word medium where your tone and body language are opaque, phrasing is really important.

For example, had your statement

And I don't use GUI builder, so just don't tell me to drag and drop the appropriate control.


been worded as:

"As I do not use a GUI builder, I'd like to know how to build such a control without the benefit of a drag-n-drop control"

I don't believe anyone would misconstrue your meaning.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have coded such a control at work. If you can wait till next monday, I might be able to give you access to its code.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss:
We have coded such a control at work. If you can wait till next monday, I might be able to give you access to its code.


I'd be very interested Ilja.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Real programmers don't use GUI builders anyway."

Ha ha! I liked that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!