button with rounded corner in java

button with rounded corner in java

Hi,

I want to create a JButton with rounded corners in swings. I went through many programs but did not got the solutions.

Thanks and regards, Vivek Birdi

View Answers

November 12, 2010 at 12:18 PM

Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.border.*;

public class ChangeButtonShape {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().setLayout(null);
JLabel l=new JLabel("Name");
final JTextField text=new JTextField(20);
JButton button = new JButton("Go");
//button.setBackground(Color.lightGray);
l.setBounds(10,10,100,20);
text.setBounds(100,10,180,20);
button.setBounds(10,40,50,20);
button.setBorder(new RoundedBorder(10));
frame.add(l);
frame.add(text);
frame.add(button);

button.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
String st=text.getText();
JOptionPane.showMessageDialog(null,"Hello "+st);
    }
});
frame.setSize(300,150);
frame.setVisible(true);
}
}
class RoundedBorder implements Border {
        int radius;
        RoundedBorder(int radius) {
            this.radius = radius;
        }
        public Insets getBorderInsets(Component c) {
            return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
        }
        public boolean isBorderOpaque() {
            return true;
        }
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            g.drawRoundRect(x,y,width-1,height-1,radius,radius);
        }
    }

Thanks


November 21, 2010 at 7:30 AM

The code sample only draws a rounded border, but the button background is still rectangular. Make the button bigger with a large arc and you'll see.









Related Tutorials/Questions & Answers:
button with rounded corner in java
button with rounded corner in java  Hi, I want to create a JButton with rounded corners in swings. I went through many programs but did not got the solutions. Thanks and regards, Vivek BirdiADS_TO_REPLACE_1
set rounded corner in a UITextView ?
set rounded corner in a UITextView ?  hello i want to know that how can i set rounded corner in a UITextView ?ADS_TO_REPLACE_1   first... you set as a radius for corner
Advertisements
How would you create a button with rounded edges?
How would you create a button with rounded edges?   How would you create a button with rounded edges?   Hi, Here is the answer,ADS_TO_REPLACE_1 We can create rounded edge button in two way's, The first thing
ModuleNotFoundError: No module named 'corner'
ModuleNotFoundError: No module named 'corner'  Hi, My Python... 'corner' How to remove the ModuleNotFoundError: No module named 'corner'... to install padas library. You can install corner python with following command
ModuleNotFoundError: No module named 'corner'
ModuleNotFoundError: No module named 'corner'  Hi, My Python... 'corner' How to remove the ModuleNotFoundError: No module named 'corner'... to install padas library. You can install corner python with following command
How to design a turn corner of the paper
How to design a turn corner of the paper
button in java
button in java  how can i compare names of two buttons after...(ActionEvent e) { System.out.println("button clicked"); } } Thanks... a beginner.I'm using simple awt components. i want to keep the labels on the button same
ModuleNotFoundError: No module named 'odoo12-addon-sale-timesheet-rounded'
ModuleNotFoundError: No module named 'odoo12-addon-sale-timesheet-rounded' ...: ModuleNotFoundError: No module named 'odoo12-addon-sale-timesheet-rounded' How to remove...-rounded' error? Thanks   Hi, In your python environment you have
ModuleNotFoundError: No module named 'normal-corner'
ModuleNotFoundError: No module named 'normal-corner'  Hi, My... 'normal-corner' How to remove the ModuleNotFoundError: No module named 'normal-corner' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'normal-corner'
ModuleNotFoundError: No module named 'normal-corner'  Hi, My... 'normal-corner' How to remove the ModuleNotFoundError: No module named 'normal-corner' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'payment-corner'
ModuleNotFoundError: No module named 'payment-corner'  Hi, My... named 'payment-corner' How to remove the ModuleNotFoundError: No module named 'payment-corner' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'payment-corner'
ModuleNotFoundError: No module named 'payment-corner'  Hi, My... named 'payment-corner' How to remove the ModuleNotFoundError: No module named 'payment-corner' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'payment-corner'
ModuleNotFoundError: No module named 'payment-corner'  Hi, My... named 'payment-corner' How to remove the ModuleNotFoundError: No module named 'payment-corner' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'payment-corner'
ModuleNotFoundError: No module named 'payment-corner'  Hi, My... named 'payment-corner' How to remove the ModuleNotFoundError: No module named 'payment-corner' error? Thanks   Hi, In your python
How to make a curl corner of the picture, make a curl corner of the picture, curl corner of the picture
How to make a curl corner of the picture       In this example, you are going to make a curl corner... a picture to curl the corner of the picture.ADS_TO_REPLACE_1 Selection: Make
java radio button and exception
java radio button and exception  Dear Sir/Madam, I have problem with my addBagelRadioButton and addCheeseRadioButton. There should be only 1 radio button can be selected, but somehow 2 can be selected the same time. Also, I
java button - Java Beginners
java button  i want to make form with checkboxes, after this i need button thich will open new pop-up page, where will be shown only this checkboxes..."); private JCheckBox cb4 = new JCheckBox("Check Box 4"); private JButton button
Button
Button  How to use image for button in JSF
java swing button click event
java swing button click event  java swing button click event   public void doClick()   Java Swing Tutorials
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can we retriving dat from database, capturing data, moving to next page.. etc
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can be retriving dat from database, capturing data, moving to next page.. etc
JRadio Button - Java Beginners
JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null); JLabel lbl1
How to turn corner of the picture
How to turn corner of the picture This is the special effect by the photoshop CS2 because it has an option to turn corner of the photograph, as I have done here. Insert Picture: Take any picture as I have
align top left corner - Development process
align top left corner  how to align top left corner   Hi friend, This is simple code Active Jump and css body { background: url(image.jpg) top left no-repeat
How to call java method on Button click in jsp?
How to call java method on Button click in jsp?  How to call java method on Button click in jsp
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings.  Hi friend, import... ActionListener { JButton button; JTextField field; public BrowsePath
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
Another Example of Gradient Paint
;    This section shows you the gradient Paint on rounded corner rectangle. A gradient is like a colored strip. It is created by specifying.... The class RoundRectangle2D defines a rectangle with rounded corners
back button issue - Java Beginners
back button issue  Hello, I have a site that asks for user and password to connect it. When the user pushs de LogOut button and later another user pushs the back button of the explorator he can entry in the page of first user
Setting icon on the button in Java
Setting icon on the button in Java   ... on the button in Java Swing. This program sets the icon on the button in Java... on the button. ImagIcon(String image_name): Above code creates an object of image
Java Button issue - Java Beginners
Java Button issue  I have this project and I have numerous steps to it. I am trying to figure out what I have to do to make my frame panel do what... is clicking the round or oval button and than perform the proper mathmathical
disable back button - Java Beginners
disable back button  I wanted the code for disabling back button in my application(The scenario is like when im in my register user page and try... displayed but..when i click back button i go back to the register page which should
Server running Button - Java Beginners
. The problem is with the display , when I run the GUI and click on the play button
Java Applet - Adding a Button to Decrease a Total
Java Applet - Adding a Button to Decrease a Total  Hello everyone... { public int testone = 0; public void init() { Button one = new Button..., it will display a button in a frame, that when clicked on will increase a total. Basically
Open website on Button Click - Java Beginners
Open website on Button Click  Hello sir I want to open website on button click using java swing plz help me sir. in my swing application one "VISIT US BUTTON" i want to open my website on Button CLick  Hi Friend
How to Hide Button using Java Swing
How to Hide Button using Java Swing  Hi, I just begin to learn java programming. How to hide the button in Java programming. Please anyone suggest or provide online example reference. Regards,   hi, In java
List the names of classes used to create button and text box in Java.
List the names of classes used to create button and text box in Java.  List the names of classes used to create button and text box in Java
wnidows button
wnidows button   How to handle windows back and forward button in struts applications, without using java script
Radio Button In Java
Radio Button In Java       Introduction In this section, you will learn how to create Radio Button on the frame. The java AWT , top-level window, are represent by the CheckBoxGroup

Ads