Home Answers Viewqa Java-Beginners button with rounded corner in java

 
 


Vivek Birdi
button with rounded corner in java
2 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners

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 Pages:
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
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 ?   first of all we have... = CornerRadius; where CornerRadius is a constant you set as a radius for corner
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, We can create rounded edge button in two way's, The first thing is to know
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
button in java
button in java  how can i compare names of two buttons after...) { System.out.println("button clicked"); } } Thanks   Hi.... i want to keep the labels on the button same yet identify them individually
wnidows button
wnidows button   How to handle windows back and forward button in struts applications, without using java script
How to design a turn corner of the paper
How to design a turn corner of the paper
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
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
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. Selection: Make selection
JRadio Button - Java Beginners
JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null); JLabel lbl1
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
iphone button example
 iphone button example In this tutorial we will tell you how to change the type of button in Interface Builder. There are six types of iPhone button, each has used for different purpose.  1. Custom  2. Rounded
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
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
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
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
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
Button
Button  How to use image for button in JSF
Radio button Validation
Radio button Validation  Hi.. How to validate radio button in java?if the radio button is not selected an error message should be given... Please...); JButton button=new JButton("Submit"); lab.setBounds(50,20,70,20
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
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
button to accept user input
button to accept user input  private void jButton1ActionPerformed... database it just gives me an error.please help   Here is java swing example... SwingExample(){ JFrame f = new JFrame("Frame in Java Swing"); f.getContentPane
Radio Button in Java
Radio Button in Java       Radio Button is a circular button on web page that can be selected by the user. The AWT  Widget used to create a radio button is Checkbox
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
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...(Icon): Above method sets the specified Icon on the button. ImagIcon(String image
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE>
iphone button change view
iphone button change view Final application will look like this:       In this tutorial will learn button change view i.e. when button is clicked will move to next view. This application is View Based
Save,Discard and Cancel button - Struts
Save,Discard and Cancel button   How can I create a confirm message with Save,Discard and Cancel button instead of OK/Cancel buttons in java script inside a jsp
how to disable browser back button
how to disable browser back button  Am doing a web application in that how to disable browser back button using java script
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
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
Create Round Button in Java swing
Create Round Button in Java swing In this tutorial, we are going to create a button of round shape. Java2D APIs and Java Swing make it easy to implement... static void main(String[] args) { JButton button = new CreateRoundButton
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
First Window
Java NotesExample - First Window This is about the simplest GUI..., and will appear in the top left corner of the screen, so you may not see it at first... to the class name including case, plus a .java extension. Main - The header for the main
add button to the frame - Swing AWT
add button to the frame  i want to add button at the bottom... JFrame implements ActionListener { JButton button = new JButton("Button...(new FlowLayout()); bottomPanel.add(myCheckBox); bottomPanel.add(button

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.