Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Vivek Birdi
button with rounded corner in java
2 Answer(s)      4 years and 2 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


Advertisement
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 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
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, We can create rounded edge button in two way's, The first thing is to know
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...) { System.out.println("button clicked"); } } Thanks   Hi.... i want to keep the labels on the button same yet identify them individually
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
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
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
java swing button click event
java swing button click event  java swing button click event   public void doClick()   Java Swing Tutorials
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
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
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
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
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
Button
Button  How to use image for button in JSF
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
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
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
Advertisements
 

 

 

DMCA.com