My own button

After adding JButtons(with an image only) to a JToolBar, I noticed that
it is unnoticable when you press it. I wanted to make my own button
which does about the same the .NET style toolbars do. The result can be found here. If anyone wants to be so freely to test it if it works on
your toolbars?
Thanks
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.*;
import java.awt.geom.*;
public class KButton extends JButton implements MouseListener
     BufferedImage bimg;
     Graphics2D g2;
     String toolTipText;
     Image image;
     int
          height, width,
          x = 2,
          y = 2,
          sp = 4; // space extra to add to sizes and stuff
     private Color fillColor = new Color(204,204,204);;
     private boolean
          isPressed = false,
          isEntered = false,
          isExited = false;
     public KButton(ImageIcon icon, String toolTipText)
          super(icon);
          this.image = icon.getImage();
          this.height = image.getHeight(this);
          this.width = image.getWidth(this);
          this.toolTipText = toolTipText;
          bimg = new BufferedImage(width + 1, height + 1, BufferedImage.TYPE_INT_RGB);
          g2 = bimg.createGraphics();
          super.setToolTipText(toolTipText);
          super.addMouseListener(this);
          super.setMaximumSize(new Dimension(width + sp,height + sp));
          super.setPreferredSize(new Dimension(width + sp, height + sp));
          super.setBorder(null);
          repaint();
     public void setBackground(Color bgc)
          this.fillColor = bgc;
     public void paint(Graphics g)
          // set the background
          g2.setPaint(fillColor);
          // clear the background
          g2.fillRect(0,0,width+sp, height+sp);
          // paint the icon to graphics 2d
          g2.drawImage(image, 0,0, this);
          // paint a border, or not
          if(isEntered)
               g2.setPaint(Color.white);
               g2.draw(new Line2D.Double(0,0, width, 0));
               g2.draw(new Line2D.Double(0,0, 0, height));
               g2.setPaint(Color.gray);
               g2.draw(new Line2D.Double(0,width, width, height));
               g2.draw(new Line2D.Double(width, 0, width, height));
          else if(isPressed)
               g2.setPaint(Color.gray);
               g2.draw(new Line2D.Double(0,0, width, 0));
               g2.draw(new Line2D.Double(0,0, 0, height));
               g2.setPaint(Color.white);
               g2.draw(new Line2D.Double(0,width, width, height));
               g2.draw(new Line2D.Double(width, 0, width, height));
          // paint the whole lotta image on the button
          g.setColor(fillColor);
          g.clearRect(0,0,width+8,height+8);
          g.drawImage(bimg, x,y, this);
     /* =====================================
     The following gives attention to actions which should be taken when the user
     presses, enters, exits or releases the mouse on the button
     ======================================== */
     public void mousePressed(MouseEvent e)
          isEntered = false;
          isPressed = true;
          x = 3;
          y = 3;
          repaint();
     public void mouseReleased(MouseEvent e)
          isPressed = false;
          x = 2;
          y = 2;
          repaint();
     public void mouseClicked(MouseEvent e)
          isPressed = false;
          isEntered = false;
          repaint();
     public void mouseEntered(MouseEvent e)
          isEntered = true;
          repaint();
     public void mouseExited(MouseEvent e)
          isEntered = false;
          repaint();

Done. Your test case works fine if you replace getCurrentDirectory() with
getSelectedFile() for the APPROVE_OPTION branch in your code. If you still
disagree with me, then please provide exact information on operating system and
java version.
import java.awt.*;
import javax.swing.*;
public class BrowserWindow extends JFrame {
    public BrowserWindow() {
        Container con = this.getContentPane();
        final JFileChooser jfc = new JFileChooser();
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int result = jfc.showDialog(this, "Save BackUp");
        switch (result) {
          case JFileChooser.APPROVE_OPTION:
            System.out.println(jfc.getSelectedFile());
            break;
          case JFileChooser.CANCEL_OPTION:
            System.out.println("Cancelled");
            break;
          case JFileChooser.ERROR_OPTION:
            break;
    public static void main(String[] args) {
        new BrowserWindow().setVisible(true);
}

Similar Messages

  • BP_CONT_SEARCH own button and own logic

    Hello,
    i need to implement a own button in the result list of component BP_CONT_SEARCH.
    Which method do i need to redifine to add my own button?
    With this button i need to read additional data to all Contact persons in the result list and export a detailed list per excel.
    What is the easiest way to get all contact persons (for example ID or GUID) in the result list?
    Thank you
    Kind regards
    Manfred

    For button creation, code in DO_PREPARE_OUTPUT of the result IMPL class after redefining. Once done. On-Click event name should be created in the same IMPL class. This method id where you will code the logic.
    Since the netity would be available from the context node RESULT, you will have the collection for all the entities. STRUCT.BP_GUID  will give you the necessary GUID of the concerned contact person.
    Rg,
    Harshit

  • Own Button in VA01/02/03 for calling an own FM to show some Information

    Hi,
    I'm looking for an EXIT to create an own button in VA01/02/03 to trigger an own FM.
    This FM shell used to give additional Information for the Materials wich are in this sales-Order.
    I don't want to update sap-standart code. I only want to use EXIT or BADI.
    Regards, Dieter

    Dieter
    This enhancement is not possible with Standard SAP..
    Thanks
    Amol Lohade

  • How to create own button for closed captioning

    Hi,
    I have created my own buttons for play, pause, exit etc. But I do not know how to create button to show closed captioning.  I tried few hours but I give up. What I need to do?:
    First clik - closed captioning will appear
    Second clik - closed captioning will disapear.
    And so on appear/disapear/appear/disapear
    Help please!
    Poul

    Have a look at: Toggle Shape buttons - Captivate 6 - Captivate blog
    Replace the system variable cpCmndMute by cpCmndCC and you'll have the choice between different scenarios.

  • Extending ContentBySearchWebPart with own buttons

    Dear all,
    I want to extend the Content Search Web Part (CSWB) with own buttons/tabs to refine the query. My idea was to derive a custom web part from the CSWB, add these buttons to the web part area and to extend the query in the button's event.
    My actual problem is to place the button to the web part area. I used the CreateChildControls() method to add my buttons (to be exact RadioButton) to the Controls collection, but the buttons will be always attached at the bottom of the web part.
    Here is my code:
    protected override void CreateChildControls()
    base.CreateChildControls();
    //create filter buttons
    for (int i = 0; i < 3; i++)
    var filter = new RadioButton();
    filter.Text = "filter " + i.ToString();
    filter.GroupName = "NewsCSWP_tabs";
    //set input properties
    filter.InputAttributes["class"] = "NewsCSWP_radio";
    //this.Controls.Add(filter);
    this.Controls.AddAt(0, filter);
    And it has the same effect if I use the .Add(...) or .AddAt(...) method. I tried also to call the base.CreateChildControls() after the Controls.Add(), but my buttons still appears at the bottom.
    What is the supported way to achive this?
    Thanks!

    Maybe its  possible, but it is not recommended to do so.
    However it does not make to much sense.
    Just run your servlet as a portal compoent with an entry as native-Servlet in the pc descriptor.
    Thats a 5 minute trip.

  • How to add my own button in the system toolbar?

    Hi,
    Is it possible to add my own button in the system toolbar which is linked to one of my own menu item ? I did a little bit search in the forum, all said it is not possible. Can anyone confirm it?
    Thanks,
    Lan

    Hi Lan,
    Your finding is correct. The toolbar is not open to UI API. We do not have any methods to change anything there.
    You may check this if you haven't: Browse Buttons in B1
    Thanks,
    Gordon

  • Design my own button in JFileChooser

    Hi
    I want my button in JFileChooser to give me the path to the directory that is selected. The thing is that I want my "save button" to do what my cancel button does. How do I do that. I cant press the "save button" if i dont select a file or a catolog containing other catalogs. Is there someting I can use like "CUSTOM_DIALOG" or something...all I want is for my program to listen for that button beeing pressed..
    As I said...pressing the cancel button executes the operation I want my save button to do...
    Heres my code:
    public class BrowserWindow extends JFrame
    public BrowserWindow()
    Container con = this.getContentPane();
              final JFileChooser jfc = new JFileChooser();
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int result = jfc.showDialog(this, "Save BackUp");
    switch (result)
    case JFileChooser.APPROVE_OPTION:
    System.out.println(jfc.getCurrentDirectory());
    break;
    case JFileChooser.CANCEL_OPTION:
    System.out.println(jfc.getCurrentDirectory());
    break;
    case JFileChooser.ERROR_OPTION:
    break;
    }

    Done. Your test case works fine if you replace getCurrentDirectory() with
    getSelectedFile() for the APPROVE_OPTION branch in your code. If you still
    disagree with me, then please provide exact information on operating system and
    java version.
    import java.awt.*;
    import javax.swing.*;
    public class BrowserWindow extends JFrame {
        public BrowserWindow() {
            Container con = this.getContentPane();
            final JFileChooser jfc = new JFileChooser();
            jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int result = jfc.showDialog(this, "Save BackUp");
            switch (result) {
              case JFileChooser.APPROVE_OPTION:
                System.out.println(jfc.getSelectedFile());
                break;
              case JFileChooser.CANCEL_OPTION:
                System.out.println("Cancelled");
                break;
              case JFileChooser.ERROR_OPTION:
                break;
        public static void main(String[] args) {
            new BrowserWindow().setVisible(true);
    }

  • How do I use my own customer Paypal buttons

    Hi everyone,
    I've set up Paypal and have managed to get Paypal's own button working. However, I'd like to use my own buttons but don't understand how to do this based on the info you've kindly given. It's the uploading my button to my hosting provider that I dont understand. What does this mean? how do I do this? My website is with Adobe Business Catalyst and my domains are through 123-reg.
    How do I 'host' a button? Are there any video tutorials on this anywhere? I need a step by step guide on this part. I need to get this up and running this week, so any info would be greatly appreciated.
    Thanks

    Yes, PayPal's buttons are quite ugly and fortunately are easy to change. All you have to do is make your own buttons (which it sounds like you have), then upload them to the images folder on your website. This requires being able to access your site through FTP, so if you don't know how to do that look it up, super easy, lots of free FTP programs out there (FTP is just a program that opens your website in a window that looks like your computer's hard drive, with your folders arranged the way you're used to).
    Once you've logged into your site through FTP (using the same username and password you'd use to upload directly through Muse), just find and double click the images folder and put your buttons in there. You have to upload your buttons to your site before this next step.
    Then, grab the original PayPal code you got for your buttons, copy it to a text file somewhere (whatever text editor you have on your computer), and look for the line that says
    <input type="image" src="
    and replace the entire text that's inside the parentheses in the src=" part with the text of where your new button images are (your button images will be in your images folder, so the text you'd replace would be whatever your website was named, like http://www.randomsite.com/images/button.png, obviously changing my example to your real website name and changing my button.png file to the real file name of your button).
    Once you've done that, copy the entire PayPal code again, all of it, not just the one line you changed, and paste that into Muse, and your new button will automatically show up. No need to place the button image as a graphic in Muse, just paste the new PayPal code and the buton automatically shows up, linking to your PayPal account.

  • How to custom my own gradient button independent of LAF?

    I want ot custom own button style independent of LAF. It should be painted with
    gradient colors. Something like metal LAF. Can you tell me how to do it?
    Thank you.

    There is a class called Gradiented and try and look at the source for the JButton in JDK1.5 this mite help
    import java.awt.Color;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class GradientButton extends JButton {
            private Color color1;
            private Color color2;
            public GradientButton() {
                    this(Color.WHITE, Color.LIGHT_GRAY);
            public GradientButton(Color c1, Color c2) {
                    this.color1 = c1;
                    this.color2 = c2;
            public void setColor1(Color c1) {
                    this.color1 = c1;
                    repaint();
            public void setColor2(Color c2) {
                    this.color2 = c2;
                    repaint();
    //       Overloaded in order to paint the background
            protected void paintComponent(Graphics g) {
                    final Graphics2D g2 = (Graphics2D) g;
                    int w = getWidth();
                    int h = getHeight();
                    GradientPaint gradient = new GradientPaint(20, 0, color1, 20, h, color2,
                                    false);
                    g2.setPaint(gradient);
                    g2.fillRect(0, 0, w, h);
            public static void main(String args[]) {
                    JFrame frame = new JFrame();
                    frame.setSize(600,400);
                    GradientButton button = new GradientButton();
                    button.setForeground(Color.BLACK);
                    button.setText("Test");        
                    frame.getContentPane().add(button);
                    frame.pack();
                    frame.setVisible(true);
    }this is not my code i just cant remember the correct Thread of it i just saved it as i thought it would be of help some time down the line.
    hope this is what you wanted

  • Using own flash button - no link option

    Hey,
    This is probably a really dumb question, but I cannot figure
    out how to link my own imported flash button to a page on my site.
    If I select a button within DW, and click the edit option I'm
    presented with the option of linking the button. If I use my own
    button, clicking edit just puts me into Flash.
    I don't want to use the "getURL" within flash because it
    insists on too many security checks which would really ruin a
    visitor's experience to my site.
    Even in code view there is no hint as to a link referenced,
    so I can't even fudge around with the code!
    Any help would be appreciated.
    Thanks.
    PS.--Adobe: maybe offer a "suggested username" when
    registering for your forums - not really my preferred choice of
    nick, but got fed up after 20 attempts to choose one.

    You cannot apply an HTML link to a Flash element. That link
    must be part of
    the Actionscript.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "Biscuit666" <[email protected]> wrote in
    message
    news:etfnt9$afg$[email protected]..
    > Hey,
    > This is probably a really dumb question, but I cannot
    figure out how to
    > link
    > my own imported flash button to a page on my site.
    >
    > If I select a button within DW, and click the edit
    option I'm presented
    > with
    > the option of linking the button. If I use my own
    button, clicking edit
    > just
    > puts me into Flash.
    >
    > I don't want to use the "getURL" within flash because it
    insists on too
    > many
    > security checks which would really ruin a visitor's
    experience to my site.
    >
    > Even in code view there is no hint as to a link
    referenced, so I can't
    > even
    > fudge around with the code!
    >
    > Any help would be appreciated.
    >
    > Thanks.
    >
    > PS.--Adobe: maybe offer a "suggested username" when
    registering for your
    > forums - not really my preferred choice of nick, but got
    fed up after 20
    > attempts to choose one.
    >
    >

  • Change Button text during component use of WDR_SELECT_OPTIONS

    Hello,
    I have implemented a WD component (WD for ABAP) by making use of component WDR_SELECT_OPTIONS. The selection screen is getting displayed. But the selection screen contains the button Copy, Check, Cancel and Reset.
    I want to rename the button tex "Copy" to "Search". Is it possible to do so?
    Please help!
    Thanks and Besd Regards,
    Maya

    Hi Maya,
    Unfortunately, this is not possible. There is also a translation bug while translating it from German into English. The button should have been translated into "Apply" instead of "Copy". This is issue is being addressed and should be fixed within one of the upcoming service packs.
    Nonetheless, there is a solution to your problem. Just hide the button (or the whole row) by calling method SET_GLOBAL_OPTIONS and add your own buttons below or above where you embed the SelectOptions component. The handler interface contains methods to reset the selection screen as well as for input validation.
    Kind regards,
    Thomas

  • Problem with buttons in shopping cart layout

    hello,
    can anyone explain what i'm doing wrong here...
    i'm simply trying to use my own buttons in the shopping cart layout but the tag descripton is appearing alongside the buttons (and the buttons don't work) after i've changed the code.
    Old code:
    {tag_clearcartbutton,<img src="/CatalystImages/shop_clearcart.png" />} {tag_buybutton,<img src="/CatalystImages/shop_checkout.png" />}
    Result:
    New code:
    {tag_clearcartbutton,<img src="/img/btn_clearcart.fw.png" />} {tag_buybutton,<img src="/img/btn_checkout.fw.png" />}
    Result:
    regards and thanks,
    Frank.

    i got this reply from Sidney (Bc) and it worked - reset the page to the default and rebuild...
    Humm strange...
    When I restore the checkout layout back to original and apply the {tag_clearcartbutton,<img alt="" src="/img/btn_clearcart.fw.png" />}  + {tag_buybutton,<img alt="" src="/img/btn_checkout.fw.png" />} reference it works fine which leads me to believe something in your current code might be conflicting. 
    I would look into this or perhaps look to restore the layout back and go from there.
    -Sidney

  • Creating a simple Flash Website - Button Problems

    I am totally new to this. Please be as detailed as possible.
    I do not know anything.
    I'm building a website using this basic model (
    http://www.oman3d.com/tutorials/flash/simple_website/).
    I tested the tutorial to become familiar with it.
    However, I want to use custom buttons that I made in
    Photoshop as links to the other pages in the website. The tutorial
    I'm using only demonstrates the use of components and parameters.
    How would I go about doing the same thing but with my own buttons?
    I've imported them as TIFF. Is that correct? Do I need to make them
    into symbols? And even then, how do I link them to the pages?
    Can you please help me or direct me to an useful tutorial
    that can better explain the process?
    Thanks so much!
    I hope I was detailed enough...let me know what info you
    need.

    Which version of Flash/actionscript are you using? Since you
    are just starting out, you should read one of Adobe's tutorials on
    the matter. Either use Flash Help to find examples on how to use
    Flash or go to their website. Here is a great tutorial for someone
    just starting out. Make sure you read all three tutorials in "Using
    Flash for the first time".
    http://www.adobe.com/devnet/flash/getting_started.html

  • How many buttons can you have in Encore?

    I'm trying to make a disc containing about 33 separate clips, all listed in the Menu, and individualy selectable. But I find when I drag buttons to the menu,it will only accept 18, then no more buttons can be added.  Is this normal for Encore?  Is there an upper limit to how many buttons you can have?

    Tim,
    I like to keep my Scene Selection Menus rather clean, and lean, so normally limit the number of Buttons for a "cleaner" look, so with, say 16 Chapters/Scenes, I will likely do 4x Scene Selection Menus, with 4 Buttons each, or maybe 3 Menus with 6 Buttons in two, and 4 Buttons in the last one.
    In the Project Panel, you can Duplicate your first Scene Selection Menu, to provide the number of Scene Selection Menus, that you need. I recommend that one Rename each duplicate Scene Selection Menu, so that it is easy to identify each one.
    Then, from the Main Menu, add a Button that goes to the first Scene Selection Menu. Do all the linking, for say the 4 Scene Selection Buttons on that, and then add a "Next Menu" Button, that links to Scene Selection Menu # 2. That one will have the 4 Scene Selection Buttons, and the "Next Menu," going to Scene Selection Menu # 3, plus a "Previous Menu" Button, going back to Scene Selection Menu # 1. [Obviously, you can name those Buttons to suit, say "Next," and "Previous," or perhaps just "arrows" pointing to the right for "Next," and to the left for "Back."
    If, for instance, one has an odd number of Scene Selection Buttons, on the last Scene Selection Menu, just "Edit in Photoshop," and Delete the "extra" Button Layer Sets.
    I also like to add my own Button names in Photoshop, rather than let Encore automatically provide the names per the names of my Timelines. For instance, I name each Timeline in numerical order, so the names will read something like this: "01_Liz_Birthday," "02_Liz_Dance," etc.. On my Scene Selection Menu, I will nave the first Button "Liz's Birthday," the second Button "Liz Dance Recital," etc., without the numerals, that just help me know which Button I will be linking to, in numerical order. I also use Photoshop to edit the Button Layer Sets name, so that Button # 1 is named "01 Liz Birthday." That gives me the numerals in the Buttons' names in my Flowchart - with intricate navigation, that takes all of the guess work out of things - all names match up, and for the Timelines, I do not have any spaces, but do in the Text for each Button. A bit more work, but when it comes time to make my links, I can do it almost instantly, with no questions in my mind. I find that a little bit of preparation at the beginning, simplifies life down the line.
    Good luck, and hope that helps.
    Hunt

  • [Feature Request] Better support for new buttons in JUNavigationBar

    In my project I use a home made sub-class of JUNavigationBar, which contains some new functionality apart from a new button as well. This button allows me to refresh the currently selected row.
    However, since I added this button though a simple this.add(), some of the functionality in JUNavigationBar may get confused.
    For example, when I have removed some of the standard buttons but left my own button in place (setHasXXX()), the component index (calculated in JToolBar) and the array index for the buttons in JUNavigationBar may not match. This occasionally causes an ArrayIndexOutOfBoundsException.
    In short, what I'm asking for, is a better way to manage buttons on JUNavigationBar. Even making the array of buttons and related methods and such protected in stead of private (so that my sub-class could handle it) would be a good start.

    Hi Arno,
    I had a similar issue with trying to create a Nav bar with dynamic content. My solution was to leave all the standard buttons in place and to use setVisible(x) to make them appear or not as required.
    BTW have you noticed that rollover behaviour isn't consistant ie works for FIRST/LAST etc but not for FIND/QUERY.
    Regards
    Andy

Maybe you are looking for