Arrow Button

Hello all,
I am trying create a button in the shape of an arrow with rounded edges, I have managed to create the rounded edges by using a RoundedRectangle as the shape of the button. However I am unable to attach a tringle at the end of the rounded rectangle to make it look like an arrow. The approximate shape I am trying to achieve is shown below:
|```````` \
|________ /
The code fragment I have written so far to create this shape is below. What I have done is subclassed a JButton, in the constructer set the shape of the button, followed by overriding the paintComponent() to paint the custom shape.
The width and heights used is worked out based on the font and the text the button will display.
The m_areaFill object is what is used by the paintComponent().
protected void setShape()
     // The rounded rectangle
     rectMain = new RoundRectangle2D.Double(0d, 0d, m_dWidthFill, m_dHeightFill, 10, 10);
     areaMain = new Area(rectMain);
     rect = new RoundRectangle2D.Double(0, 0, m_dWidthFill - 30, m_dHeightFill, 10, 10);
     areaMain.add(new Area(rect));
     Point p1 = new Point(((int)m_dWidthFill - 30), 0);
     Point p2 = new Point(((int)m_dWidthFill - 30), (int)m_dWidthFill);
     Point p3 = new Point((int)m_dWidthFill, ((int)m_dWidthFill/2));
     int[] xs = { p1.x, p2.x, p3.x };
     int[] ys = { p1.y, p2.y, p3.y };
     Polygon triangle = new Polygon(xs, ys, xs.length);
     areaMain.add(new Area(triangle));
protected void paintComponent(Graphics g)
     Graphics2D g2 = (Graphics2D) g;
     RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, enderingHints.VALUE_ANTIALIAS_ON);
     g2.setRenderingHints(hints);
     if (getModel().isArmed())
          g2.setColor(Color.gray);
     else
          g2.setColor(Color.lightGray);
     g2.fill(areaMain);
     super.paintComponent(g2);
}Firstly what I would like to ask is am I taking the correct approach to create the arrow button, or is there another approach I should be taking. Also if this is a good enough approach how would I add triangle (the arrow head) to the rounded rectangle.
Kind Regards Mark

You are calling super.paintComponent(g) at the end of paintComponent, this is overriding what you are trying to draw. Also, I would use a GeneralPath for the shape you want - see revised code below:
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.font.*;
public class Main
    public static void main(String[] args)
        TestFrame main_Frame = new TestFrame();
        main_Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        main_Frame.setVisible(true);
class TestFrame extends JFrame
    public TestFrame()
        setTitle("Test Frame");
        setSize(500, 500);
        JPanel panel = new JPanel();
        ArrowButton button = new ArrowButton("Button One");
        panel.add(button);
        add(panel);
class ArrowButton extends JButton
    public ArrowButton(String text)
        super(text);
        setPreferredSize(new Dimension(m_dWidthFill, m_dHeightFill));
        setShape();
    protected void setShape()
        path = new GeneralPath();
        double x1 = 10;
        double y1 = 0;
        double x2 = m_dWidthFill - 30;
        double y2 = 0;
        double x3 = m_dWidthFill;
        double y3 = m_dHeightFill/2;
        double x4 = m_dWidthFill - 30;
        double y4 = m_dHeightFill;
        double x5 = 10;
        double y5 = m_dHeightFill;
        double x6 = 0;
        double y6 = m_dHeightFill - 10;
        double x7 = 0;
        double y7 = 10;
        //Lower Left Bessel points
        double bax5 = x5;
        double bay5 = y5;
        double bbx5 = 0;
        double bby5 = m_dHeightFill;
        //Upper Left Bessel points
        double bax7 = x7;
        double bay7 = y7;
        double bbx7 = 0;
        double bby7 = 0;
        path.moveTo(x2, y2);
        path.lineTo(x3, y3);
        path.lineTo(x4, y4);
        path.lineTo(x5, y5);
        path.curveTo(bax5, bay5, bbx5, bby5, x6, y6);
        path.lineTo(x7, y7);
        path.curveTo(bax7, bay7, bbx7, bby7, x1, y1);
        path.closePath();
    protected void paintBorder(Graphics g){}
    protected void paintComponent(Graphics g)
     Graphics2D g2 = (Graphics2D) g;
     RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     g2.setRenderingHints(hints);
     if (getModel().isArmed())
          g2.setColor(Color.GRAY);
     else
          g2.setColor(Color.LIGHT_GRAY);
     g2.fill(path);
        FontRenderContext context = g2.getFontRenderContext();
        Rectangle2D rect = font.getStringBounds(getText(), context);
        int x = 10;
        int y = (int)((m_dHeightFill+rect.getHeight()/2)/2);
        g2.setFont(font);
        g2.setColor(Color.BLACK);
        g2.drawString(getText(), x, y);
    private int m_dWidthFill = 120;
    private int m_dHeightFill = 50;
    private GeneralPath path;
    private Font font = new Font("Times New Roman", Font.BOLD, 16);
}

Similar Messages

  • I have set up my airprint wifi printer which works perfectly with the HP eprint app. However, when i view an email and click on the top right arrow button and select "PRINT" on my ipad nothing happens????...

    I have set up my airprint wifi printer which works perfectly with the HP eprint app. However, when i view an email and click on the top right arrow button and select "PRINT" on my ipad nothing happens????...
    Also, when im viewing websites and i find something i wish to print, same again, if i simply click on the print option at the top right of the screen nothing happens... the only way I can print is if i copy the weblink of the site page then click on my HP eprint app and paste the web link, then select print, it prints off fine.. but its it such a pain to keep copying and pasting links or screen dumping emails just to print...

    Just to recap, this is a collection of ports I have collected over time for people who needed this information when setting up the HP ePrint app so that they could view their email from within the app.  I am certain other applications also need this information.  Although lengthy, I could not find a more comprehensive place to retrieve this information.  Feel free to post additional information, faulty information, or other related topics below as this is simply a collection of data and it would be practically impossible to test all of them. Thank you!
    Don't forgot to say thanks by giving "Kudos" if I helped solve your problem.
    When a solution is found please mark the post that solves your issue.
    Every problem has a solution!

  • How can I make appear the arrow-button that showed the recent history of a same tab (next to back and forward buttons)?

    for instance, if I searched a word on google, then clicked on a certain page of the results, then inside that page I entered a link, etc if I wanted to "go back" directly to the instance of google searching I could click on this arrow-button and I would be able to choose that exact moment instead of clicking several times on the "back" till I reached the desired past page

    The arrow to open the tab history of the Back and Forward buttons has been removed in Firefox 4 and later.
    Use one of these methods to open the tab history list:
    * Right click on the Back or Forward button
    * Hold down the left mouse button on the enabled Back or Forward button until the list opens
    You can look at this extension:
    * Backward Forward History Dropdown: https://addons.mozilla.org/firefox/addon/backforedrop/

  • After I search using Google in Firefox, and hit the back arrow button to return to the main homepage I use, the browser won't take me there. Instead, I'm left at the initial results page from my search.

    Assume I start at Google as my homepage. I search for Federal Reserve. Google then brings up a number of selections for Federal Reserve. I can scroll through to more search results on page 2, 3, 4, etc. Now suppose I want to use the back arrow button to go back to Google as my homepage. I’ve found what I was looking for. When I try to get back to Google, the furthest back I can go is to page 1 of the search results. The browser won’t take me back to the original starting page which was Google. Also, it doesn’t matter what the starting page or initial page was. The browser will only take me back to the initial page after the original homepage. By the way, I did not install any new software or applications prior to this problem occurring. My guess is that it may have something to do with the function keys at the top of the keyboard. But I can’t figure out what the problem is with the function keys. It’s only a guess.

    using Google toolbar for searches?? disable instant search (click the wrench to the right of the tool bar, untick enable instant, and hit save. worked for me
    :

  • When I type an address in the location bar and hit Enter nothing happens. I must click the arrow button at the end of the location bar. How do I fix it so that the Enter key works?

    When I type a web address in the location bar and hit enter nothing happens. In order to go to the website I've typed in, I must click the arrow button at the end of the location bar. How do I make it so that hitting the enter key takes me to the web page.
    == This happened ==
    Every time Firefox opened
    == Since Firefox 4 Beta installed an update

    The AVG addon seems to have caused the problem for me. I had it disabled and everything worked. Then I updated to AVG 2011 and the problem occurred. It seems to have reenabled itself after the update.
    Just disabling it solved the problem.

  • Trying to connect my iphone 4 to my home wifi network! my android phone gives me the option of pushing the arrows button on my router and on my android phone but cannot find the "push the arrows button" option on my iphone 4. is this option available???

    trying to connect my iphone 4 to my home wifi network! my android phone gives me the option of pushing the arrows button on my router and on my android phone but cannot find the "push the arrows button" option on my iphone 4. is this option available?? and if so, where is it located???

    No such option on an iPhone.  Just go to Settings>wifi, tap the name (SSID) of your your home network from the list, then when prompted, enter the password.

  • Arrow buttons with fade effect

    I have made arrow buttons on each side of a document I intend to export to pdf.  They are set to behave so that when the reader of the pdf clicks on one of them it takes them to the previous or to the next page. the issue I have is that they are distracting.  Is it possible to auto-fade these buttons and when you mouse over them they fade into view?

    I've made the buttons and they work fine. I found this link also helpful...http://www.dynamicgraphics.com/dgm/Article/28696
    The last issue is dotted outlines that appear when I push the button in the pdf. It looks like the dotted lines came from indesign with the objects. I've attached a photo. Not so important but if there was an easy way to get rid of them that would be great. Thanks again for the help.

  • Arrow buttons not working.

    Arrow buttons stopped working once I upgraded to Mountain Lion.   I thought Mavericks would fix.  No luck.    Any ideas?  If I look in input sources, there are no arrow keys on the keyboard illustrations for US or US extended keyboards. 

    If a hard reset didn't work, you probably need to restore the iPhone.

  • Enchancement Request: IR arrow button in Search Filter uses applied Filters

    Hello,
    I'd like to request an Enhancement.
    I'd like the IR arrow button in IR Search Filter, when performs the DISTINCT to provide choices in list for the user to select, that would take into consideration any other Filters that have already been applied to the IR Report in.
    Currently it seems that it ignores any of these already applied filters and provides the DISTINCT list of the default report settings row set.
    Referencing thread:
    How to display values in arrow in Filter in IR for joined table columns ?
    TIA
    Dionyssis

    Ah ha! I figured out a solution. It took one of those "ah ha" moments to do it.
    Peter.... thanx for the suggestion, but I am using the built-in Interactive Report settings to hide the Actions button and other things. I am also attempting to hide the section on the page which displays the current filtering, control breaks, etc. that are applied to the report. This is because the page is a public page and needs to be as simple as possible and I do not want the end users to have the ability to turn pre-built filtering and control breaks on and off. The problem is that the user-entered filtering is displayed in the same place as the pre-built filtering and I want to display the former, but not the latter.
    I created a display-only item on the page containing the text that should show when the user has entered some search criteria in the search box. I then created a dynamic action which is triggered by the refresh of the interactive report and runs some javascript which first checks if there is "custom search criteria" applied and then hides or shows the display item accordingly. My javascript code is below for those interested.
    if ( $('#apexir_CONTROL_PANEL_COMPLETE .fielddata:contains("Row text contains")').text() )
    { $x_Show('P1510_FILTER_ENABLED') } else { $x_Hide ('P1510_FILTER_ENABLED') }Shane.

  • Arrow buttons missing from the scrollbars!

    Does anyone know of anyway including a third party extension to return arrow buttons to the scrollbrs?
    Lion has what is a fatal flaw to me. There are no arrow buttons in the scrollbars. Not even an option for them!
    I am aware of all the other ways to scroll, so don't waste our time telling me about them.
    When I am reading a web page, I want to to be able to click down one line at a time until the paragraph at the bottom is not cut off, then click in the scrollbar to go down a page. And repeat.
    Scrolling with a scrollwheel or trackpad lacks the precision of clicking the arrow button or clicking in the scrollbar to go down a page. It is to easy to undershoot or overshoot exactly where I want to go which is one line down at a time. This means is takes longer to do scrolling than clicking the arrow button.
    I also know you can go down one line at a time with the arrow keys, but this requires taking my hand off the mouse which also takes longer and is extremely annoying.
    Not having arrow buttons in the scrollbar is intolerable! I use them constantly, and if I can't scroll windows then I can't use the computer. So this makes any improvements that Lion may have worthless.
    Give a fraking option for arrow buttons in the scrollbars!
    p.s. As of this writing, there is no option to give feedback for 10.7 on the Mac OS X feedback page.

    I agree.  I use a program that relies on the arrow buttons for precise nagivation, and now that they're gone, it makes my work twice as time-consuming.
    At least with "natural scrolling" (Ha--it's like building a car that steers by pushing left to turn right, because that's how skateboarders do it) you can turn of the setting, or download Scroll Reverser.  But this, there's no option.
    They need to fix this, or else I have to go back to Snow Leopard and tell the others who use the program I use that they can't upgrade unless the arrows are back.

  • JComboBox - Hide/Show Arrow Button

    hello all,
    im stuck. i want a jcombobox to have its arrow button hidden unless the mouse is over it
    rite now i have the jcombobox implenting the mouselistener . but i have no idea how to get the object to show/hide the arrow button. i read something about using the ComboBoxUI to hide the button but thatz pernament rite? unless i keep refreshing the ui whenever the mouse moves in or out of the object
    any advice will be greatly appreciated.
    thx

    Open src.zip with Winzip. Look at BasicComboBoxUI.java. Figure out what changes you need to make to make the button disappear. It probably can be done pretty easily if you pick the right spot to change. But don't change BasicComboBoxUI.java. Write your own class that extends BasicComboBoxUI and override the method you picked to change. You may end up rewriting the whole method or just calling super.whatever() and then tweaking.

  • Changing color of arrow button in JComboBox

    Hi all,
    Can somebody please help me to change the color of arrow button in JComboBox

    The default color uses to draw the arrow is UIManager.getColor("controlShadow"), so if you put a different color there, that would be used for the arrow buttons. Of course, that color is likely used other places as well, and so any other place where it is used would get your changed color too. For example, the scrollbar buttons for the scrollbar in the popup list would likely use that color.
    Further, the current look and feel can override this; for example, the Metal L&F creates its own button, which uses its own icon which ends up using a hard-coded color of black when painting the arrow.
    : jay

  • Make my movie clip move from left to right with arrow buttons.

    Hi hope this is a quick one..
    I have all the elements set up already so just need the
    logistics of how i can acheive the following:
    I have an arrow at the furthest left and furthest right of my
    main flash movie. I then have a movie clip in the middle which has
    indidivual images on a kind of long strip. When i click the left
    arrow i want the movie to begin to move from the right to the left
    and visa versa. I have achieved this with the keyboard left and
    right keys so what i really need is to convert this theory for the
    left and right arrow buttons?
    var speed:Number = 4;
    object_mc.onEnterFrame = function() {
    if (Key.isDown(Key.RIGHT)) {
    this._x = this._x+speed;
    } else if (Key.isDown(Key.LEFT)) {
    this._x = this._x-speed;
    Any help will be greatly appreciated??
    Thanks
    Ben

    use the getAscii() or getCode() methods of the key class. and
    you can always use the trace function to check the values to be
    used in your if-statement.

  • Down Arrow button is blurr in CRM 2013

    Hi ,
    I am using CRM 2013.
    See, the Down arrow buttons, in above screen shot, all are blurred.
    I dont know, whats wrong with it. Any suggestion to resolve this resolution issue ?
    Thanks!!!
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Hi,
    Have you tested accessing your CRM from another browser in order to replicate this bug?
    Could it be your zoom settings are off the default for the current browser?
    Edit: Refreshing the page doesn't help? Perhaps clear the browser's cache?
    Hope that helps,

  • I just went from OS 10.6 to 10.8. The arrow button is gone from the scrollbar. I do not see the option in "Systems Preference" any more. Am I missing something. If it is gone, is Apple going to bring it back?

    I just went from OS 10.6 to 10.8. The arrow button is gone from the scrollbar. I do not see the option in "Systems Preference" any more. Am I missing something. If it is gone, is Apple going to bring it back?

    John R M wrote:
    Thank you. I believe Apple shoud give you the option as to whether or not you may want to use the arrows.
    Apple give users what they want?
    Good luck there, the head of iOS Scott Forstall was canned, I suspect this was his favorite picture.
    However I bring salvation and sanity, the option to go back to the wonderous Snow Kitty.
    How to revert your Mac to Snow Leopard
    How to erase and install Snow Leopard 10.6
    Be sure to vent to Apple for the stupid changes here
    https://www.apple.com/feedback/macosx.html

Maybe you are looking for

  • Would like to move the MBAM reports up a level in the folder structure

    We have MBAM 2.5 using CfgMgr 2012 integration all set up and working. In the reports I had this structure: -Reports --MBAM ---en-us ----Compliance Details ----Compliance Summary ----Compliance ----Compliance Dashboard To save one level of drilling d

  • Photoshop Camera Raw 6.7-Update Installation failed

    Photoshop Camera Raw 6.7-Update Installation failes. System information: Adobe Photoshop Version: 12.0.4 (12.0.4x20110407 [20110407.r.1265 2011/04/07:02:00:00 cutoff; r branch]) x32 Operating system: Windows XP 32-Bit Version: 5.1 Service Pack 3 Regi

  • Airport Express -- old model vs new - question

    On the Ariport Express Wiki page,  it states that the old model A108x does not have "Wireless-to-Ethernet Bridge mode" while the newer (A1264) model has it.  If in fact the newer model does have this,  what does it allow one to do vs having the older

  • Passing Internal Table to a Function Module.

    I am new to Web Dynpro Abap. Using the Function Builder, I am trying to pass an Internal Table (IT) as an import parameter into my Function Module (FM), fill it within the FM and be able to recieve the filled IT back as an Export parameter from the F

  • Finding errors in IDOC

    Hi all, Plz tell me how to see the errors displayed in IDOCs. Thanks Venkat