Changing the JButton shape

Hi All,
The shape of JButton is usually a rectangle
=========
btnName
=========
but I want to change it's shape to Triangle or Circle like this
o
oooo
o o
o bntN o
ooooooooooo
can I do that with swing?
Please help.
Thanks,
Long

The easiest thing to do would be to create a triangular icon and put it on your button, then make the background of the button the same color as the background of the rest of your page. You may also need to remove the border by doing
setMargin(new Insets(0, 0, 0, 0));

Similar Messages

  • Know how to change the outline shape of a tooltip?

    Hi All,
    I was wondering if anybody knows how to change the shape of a tooltip popup box?
    I've implemented my own UI delegate for ToolTipUI and overridden the paint( Graphics g, JComponent c ) method which I thought would have allowed me to completely control the rendering of the tooltip, box and all. But what I discovered was that even when I did nothing inside this method, the rectangular popup window was still appearing (I stepped through the code, and the correct instance of UI was being used, not the one that may have been defined by UIManager.set( "ToolTipUI", "foo.Bar" )) After a little more investigation, I ended up in ToolTipManager.showTipWindow() which eventually calls
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    tipWindow = popupFactory.getPopup(insideComponent, tip, location.x, location.y);
    tipWindow.show();To try to overcome this, as a test I extended JButton with the following constructor:
    public TestButton() {
        super();
        setUI( new MyCustomUI() );
        ToolTipManager.sharedInstance().unregisterComponent( this );
    }but this didn't solve the problem either. Has anybody got any ideas on this?
    Cheers,
    Paul.

    Try this.
    regards,
    Stas
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    public class Test {
        JScrollPane scroll;
        JPanel p=new JPanel(new BorderLayout());
        Robot robot=new Robot();
        public Test()  throws Exception {
            final JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(p);
            JButton b=new JButton("Test balloon!");
            b.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    TransparentFrame frame1=new TransparentFrame();
                    int x=frame.getX()-100;
                    if (x<0) x=0;
                    int y=frame.getY()-100;
                    if (y<0) y=0;
                    frame1.setBounds(x,y,100,100);
                    frame1.createBalloon();
                    frame1.setVisible(true);
            frame.getContentPane().add(b);
            frame.setBounds(200,200,120,50);
            frame.show();
        public static void main(String[] args) throws Exception {
            new Test();
    class TransparentFrame extends JWindow {
        Robot robot;
        BufferedImage screenImg;
        Rectangle screenRect;
        MyPanel contentPanel=new MyPanel();
        boolean userActivate=false;
        Area Balloon;
        public TransparentFrame() {
            super();
            createScreenImage();
            contentPanel.Balloon=Balloon;
            this.setContentPane(contentPanel);
            this.addComponentListener(new ComponentAdapter() {
                public void componentHidden(ComponentEvent e) {}
                public void componentMoved(ComponentEvent e) {
                    resetUnderImg();
                    repaint();
                public void componentResized(ComponentEvent e) {
                    resetUnderImg();
                    repaint();
                public void componentShown(ComponentEvent e) {}
            this.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                public void windowClosed(WindowEvent e) {
                public void windowOpened(WindowEvent e) {
                public void windowIconified(WindowEvent e) {
                public void windowDeiconified(WindowEvent e) {
                public void windowActivated(WindowEvent e) {
                public void windowDeactivated(WindowEvent e) {
                    Balloon=null;
        protected void createScreenImage() {
            try {
                if (robot==null)
                    robot=new Robot();
            catch (AWTException ex) {
                ex.printStackTrace();
            Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
            screenRect=new Rectangle(0,0,screenSize.width,screenSize.height);
            screenImg=robot.createScreenCapture(screenRect);
        public void createBalloon() {
            Rectangle bounds=new Rectangle(0,0,getWidth(),getHeight());
            Balloon=new Area(new Rectangle(bounds));
            System.err.println(Balloon.getBounds());
            RoundRectangle2D content=new RoundRectangle2D.Double(0,0,getWidth(),getHeight()/3,20,20);
            Polygon polygon=new Polygon(new int[] {20,getWidth()/2,getWidth()},new int[] {getHeight()/3,getHeight()/3,getHeight()},3);
            Area a=new Area(new Rectangle(bounds));
            a.subtract(new Area(content));
            a.subtract(new Area(polygon));
            Balloon.subtract(a);
            contentPanel.Balloon=Balloon;
        public void resetUnderImg() {
            if (robot!=null && screenImg!=null) {
                Rectangle frameRect=getBounds();
                int x=frameRect.x;
                contentPanel.paintX=0;
                contentPanel.paintY=0;
                if (x<0) {
                    contentPanel.paintX=-x;
                    x=0;
                int y=frameRect.y;
                if (y<0) {
                    contentPanel.paintY=-y;
                    y=0;
                int w=frameRect.width;
                if (x+w>screenImg.getWidth())
                    w=screenImg.getWidth()-x;
                int h=frameRect.height;
                if (y+h>screenImg.getHeight())
                    h=screenImg.getHeight()-y;
                contentPanel.underFrameImg=screenImg.getSubimage(x,y,w,h);
    class MyPanel extends JPanel {
        BufferedImage underFrameImg;
        Area Balloon;
        int paintX=0;
        int paintY=0;
        public MyPanel() {
            super();
            setOpaque(true);
        public void paint(Graphics g) {
            super.paint(g);
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(underFrameImg,paintX,paintY,null);
            if (Balloon!=null) {
                g.setColor(Color.yellow);
                ((Graphics2D)g).fill(Balloon);
            g.setColor(Color.red);
            g.drawString("Balloon test!",10,20);
    }

  • Changing the cursor shape

    how can i change the shape of a cursor to "hand" when the mouse rolls over specific text item. i have tried the cursor_style property but it returns only some of the cursor styles plus the are just behind the mouse clik trigeers so it chnges the shape when the mouse is cliked while i want it to change when mouse just rolls over the specific text item.as done in hyperlinks .

    Which form version you are using?
    Forms 6, has got cursor styles which are HAND, MOVE not documented in help.
    SET_APPLICATION_PROPERTY(CURSOR_STYLE,'HAND');
    regards

  • Changing the image shape of an FCP output

    Hey there,
    I'm using FCP HD with OS10.4 on a Powermac g5. I generally just work with dv footage.
    I want to output a media file that has specific ratio/ dimensions (proportional to 288 pixels wide and 1, 520 pixels high, ie, an unpended rectangle). These have to be the actual dimension of the file/ image, rather than the shape of the image if cropped inside a standard ratio.
    How do I control the output ratio/ dimensions? Is this something you can set? I can only see the PAL/ntsc etc ratios... anyone out there help?
    Many thanks!
    Best
    Richard

    Not a totally stupid question...I'd assume you have a reason for doing this...
    Provided you understand what this is going to do to your image...you would do the following:
    File / Export / Using Quicktime Conversion
    Format - Quicktime Movie (unless you require some other format)
    Click on 'Option' button and click on the 'Settings button in the Video section. You can designate a type of compression...Video, Animation, TGA, DV-NTSC...etc.
    Click OK, then click on the 'Size' button in the video section.
    Click the Dimensions button and choose Custom at bottom, then type in your 288x1520. You would now choose to select Preserve Aspect ratio using - Letterbox, Crop or Fit within dimensions.
    Click OK, OK, name the file and hit save.
    Tada...hopefully the image you're working with will look good, either very small or very squeezed...depending on your choice of aspect ratio...and how it's to be presented.
    ; ]

  • How can i change the JButton look?

    I like to create a new button class "LinkButton".
    So that the buttons gets a link look.
    But i can not set the button "background" disable.
    ++++++++++++++++++++++++++++++++
    package GUI;
    import javax.swing.*;
    public class LinkButton extends JButton {
         public LinkButton (String Title){
              super (Title);
              setBackground(null);
              setBorder(null);
              setLayout(null);
              setFont(null);
              setForeground(null);
              setDefaultCapable(false);
              setBorderPainted(false);
              setDisabledIcon(null);
              setDisabledSelectedIcon(null);
              setFocusPainted(false);
              setIcon(null);
         }

    setContentAreaFilled (false);Method inherited from AbstractButton.
    The exact behavior of calling this function varies on a component-by-component and L&F-by-L&F basis.
    db
    edit And why does the API refer to this as a function especially as it returns void?
    Edited by: Darryl.Burke

  • How do i change the area of a text box (containg text) with the new 'shapes' transform tool..

    the new Illustrator CC 2014 wont let me change the area of a  text box, the text scales with the box.
    is there a setting im missing somewhere that allows me to change the area /shape of a text box like we could in CC and before?

    edit>preferences>type> uncheck "Auto size new area type"

  • Trying to change the shape of a brush

    When I click the brush tool the "Edit" is grayed out next to the "New". How
    do I change a brush shape?

    You can't change the brush shape. It's a round brush.

  • Changing the default capture captions

    Hi there,
    I have made some demos and changed the caption styles accordingly. wWhile I have changed the styles and set them to be default, when I do a recording, the new captions appear OK, but they do not have the speech arrow automically like the default Captivate onese do, which means I need to go through and change all of them to have a pointer.
    As per below images, the default one puts the callout already with the little pointer but the custom one does not. Naturally you can change the calloout shape afterwards bu that can be painstakingly slow over many many slides.
    Is ther a way I can get my captions to totally have the same behavoiur as the Adobe Captivate ones??
    Cheers
    Rossco

    Hello Rossco,
    Callout type is decided based on the action you are doing. If you are clicking somewhere then the callout would have the arrow pointing to the clicked location. If there is a dialog opening then the callout would be plain without any arrow.
    If you want to change the look of these captions before recording, then you can go to preferences>Recording>Defaults and set some other style for the text caption.
    Is this something you are looking for?
    BTW, if you want to have the .pcm file for your own caption, then I suggest you to duplicate the existing ones under /galley/Captions. Make sure to follow the naming convention of 1,2,3…
    Thanks,
    Vish

  • Change the color of the outer line of a shape

    Hello I'm trying to create a rectangle with a red border and no inside fill. It's only to highlight some text of a bank form.
    I know i have to right click the layer and choose blending options and stroke. But I've tried to change the color so many times and no matter what I do, the outer line remains gray and with rounded corners.
    I want the corners of the rectangle to be squared, not rounded but I'm having a hard time changing this.
    Please help
    I'm using Photoshop CS3
    thank you
    Could anyone please show a picture of where to change the color of the outer line? I've tried everything.

    Hi,
    With Ps CS3, you'll probably want to define a Layer Style for a Stroke and then use that with the Square Shape Layers.
    This is a Stroke of 4 px, 'Centered' (so a very slight corner rounding on the outside edge. 'Inside' will give you square corners for both inside and outside edges). To change the color of the stroke, go to Layer> Layer Style> Stroke and change the color by clicking on the color bar.
    regards,
    steve 

  • How do I change the Background Color of a Shape in iWeb?

    I am adding a comment bubble from the Shape menu for one of my photos. Everytime I try to change the background color of the bubble I end up changing the entire background color of the Web Page.
    How do I only change the background color of the shape?
    G5   Mac OS X (10.4.4)  

    Hi Kyn,
    Perhaps you (or anyone else!) can help me with this too: is it possible to change the color of the border styles that you choose for the thumbnails on a photo page? There is no "fill" option in the Graphic pane of the inspector when I select one of them. I love some of the styles but would like to be able to match the color better to my pages. See here for an example:
    http://web.mac.com/mousie/iWeb/Site/Recount.html
    The twirly border is a little too orange for my taste.
    Thanks in advance.

  • How do I change the colour of a page in Pages without using a floating shape or text box?

    I want to change the colour of a page in Pages without having to stretch out a floating coloured shape or using a text box to write the text in. I have been stretching shapes and using text boxes for years but surely there is an simpler and more elegant way to do this? Plus, I want to be able to type several pages of continuous text and not have to split the text up into multiple text boxes. Any help most welcome.

    bigj wrote:
    I want to change the colour of a page in Pages without having to stretch out a floating coloured shape or using a text box to write the text in. I have been stretching shapes and using text boxes for years but surely there is an simpler and more elegant way to do this?
    There are a whole lot more really essential features missing in Pages than this.
    bigj wrote:
    Plus, I want to be able to type several pages of continuous text and not have to split the text up into multiple text boxes. Any help most welcome.
    What is stopping you?
    Peter

  • How do I change the units for the vector shape stroke in the option bar?

    I work with vector shapes very often in Photoshop. In CS6, they have added the stroke and fill tools in the option bar.
    If I open a file with vector shapes that was created in CS5, the stroke defaults to 3pt. I would prefer it to default to pixels instead of points. I have found that if I change the settings prior to creating a new shape, it retains those attributes for all future shapes. However, if I am working on an older file, and would like to use this tool, it is frustrating to have to change this unit every time.
    Any assistance would be helpful. Thanks!

    Every time I move the volume, it moves back!
    Check, if you have a volume automation set on the software instrument track.
    If the track volume automation curve is enabled, the volume slider for the track will move with the automation curve.
    Click the automation curves disclosure triangle in the track header and disable the volume automation.

  • How do I change the width of shape lines

    I created a pattern in Photoshop CS6 for a project with shape lines which reside on shape layers. I want to change the line weight but after I create them it seems there is no way of changing the shape; even after I select line.
    I can change the spread (uniform distribution) of the lines and lengh but not their weight. No matter if I choose all or just one of the lines which are all on the same shape layer the weight does not change. This does not make sense. Can somebody please chime in.
    Ed Carreon
    www.carreonphotography.com

    If you used the Line Tool, then you really created rectangles and the "Weight" option does not modify existing Lines. Scaling them simultaneously to become narrower/wider rectangles then redistributing them may solve your problem (their CS6 stroke attribute may complicate matters) so try that first.

  • How can I change the shape of a photo in iPhoto?

    Can I change the shape of a picture to an oval?

    No. You'd need an external editor for that kind of stuff:
    In order of price here are some suggestions:
    Seashore (free)
    The Gimp (free)
    Graphic Coverter ($45 approx)
    Acorn ($50 approx)
    Pixelmator ($50 approx)
    Photoshop Elements ($75 approx)
    There are many, many other options. Search on MacUpdate or the App Store.
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    Of course, you may not want to change the shape of a photo which would distort it. You may want to print it in an oval shape but undistorted. I'd use a page layout app like Pages for that,

  • How do you change the text of a JButton?

    This question probably has a simple answer. If I've already created multiple JButtons with no text inside them and I want to change the text inside them later, what method do I call?

    ksg089 wrote:
    This question probably has a simple answer. If I've already created multiple JButtons with no text inside them and I want to change the text inside them later, what method do I call?Someone will give you the direct answer, but the best answer is this: learn to read the API. This is a skill that will help you immensely more than my just telling you the method. It's a "set" method, I believe that it is in one of JButton's ancestors (AbstractButton?), and when you see it, it will be obvious to you that this is the solution. Good luck!
    the link is [here.|http://java.sun.com/javase/6/docs/api/javax/swing/JButton.html]
    Edited by: Encephalopathic on Mar 28, 2008 10:25 PM

Maybe you are looking for

  • Sales Report Generation less the Credit memo

    Anybody can help me regarding Query for Sales Report. Im trying to create a sales report per Per Product and Customer with corresponding Quantity and Amount, I have already get the query the problem is I cant get the Credit Memo deduct from its A./P

  • Navigational Attribute in Reporting

    Hi experts, Suppose I have created one attribute as navigational attribute in my infoobject characteristic.This Characteristic is in Infocube. Now after executing query on this infocube,Can I drilldown from thic characteristic to Navigational attribu

  • IChat status changes to running app!

    Hello all, Suddenly, iChat (v4.0.8 (619), Leopard 10.5.7) has started changing my status to whatever application I run or switch to. It flips between "Finder", "Safari", "iChat", whatever! Has anyone seen this behavior? I didn't "set" it, and can't f

  • A good equipment and software for making music

    Hello! This is the situation: I´m using Garageband ´08 for making (good?) music, a USB-powered keyboard and the laptop stated below. How would you suggest I'd do to get more instruments and better performance when editing music and playing it in real

  • My iMovie project is in the finder but will not open!

    I was finishing up a project in iMovie '11 that I had been working on for several weeks, when my computer made me restart. When I reopened iMovie my older projects were listed but this one was gone. I went into the finder and found the project still