Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField/JPanel with round edged corners  RSS feed

 
Premila
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai everyone,
In my application i need to have JtextFields/ JPanels
which are rounded rectangle in shape ie. with rounded edged
border. Any means to achieve this. Please help. Awaiting
valuable helps in this regard.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The thread "custom buttons" covers creating your own rounded borders for components. However, I'm not sure that's all you'll need to do for JTextField. You may have to go into designing a new component, as well as a rounded border, because when I tried it, the text areas still came up as rectangular.
I do have some completed code for a rounded border if you would like it.
regards,
Ben.
 
Premila
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for ur response.I can't get u. It will be very helpful to me if u give the code u have.
Regards,
Premila Viswanathan
Originally posted by Ben Wood:
Hi,
The thread "custom buttons" covers creating your own rounded borders for components. However, I'm not sure that's all you'll need to do for JTextField. You may have to go into designing a new component, as well as a rounded border, because when I tried it, the text areas still came up as rectangular.
I do have some completed code for a rounded border if you would like it.
regards,
Ben.

 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You'll find the class I have put together for creating a rounded border below. To create a round border, pass a value of true for roundc - there's an example after the code:

Apply the border in the following way e.g....

regards,
Ben

ps:
Edited
mybutton.setBorder(new SubtleSquareButton(true));
to be
mybutton.setBorder(new SubtleSquareBorder(true));
Assumed this was a typo, Ben.
- satya

[This message has been edited by Madhav Lakkapragada (edited September 10, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"Premila"
your name doesn't agree with the javaranch guidelines.
please take a moment and re-register after reviewing the
guidelines at http://www.javaranch.com/name.jsp
thanks for your cooperation.
- satya
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies! You assume correctly.
Thanks,
Ben.
 
Premila
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr.Ben
Sorry for the late reply. i didn't check for the replies for the last few weeks. However i was able to solve my problem with
the following coding:
import java.awt.Color;
import javax.swing.border.LineBorder;
import java.awt.Component;
import java.awt.Graphics;
public class RoundEdgedBorder extends LineBorder
{
int arcWidth=35,arcHeight=35;
Color fillColor=new Color(250,243,215);

public RoundEdgedBorder() {
super(Color.red);
}



public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
g.setColor(fillColor);
g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
}
}

while using the code is like:
panel.setBorder(new RoundEdgedBorder());

Note: My application needs rounded edged filled(fill color rgb: 250,243,215) panels.

Originally posted by Ben Wood:
[B]Hi,
You'll find the class I have put together for creating a rounded border below. To create a round border, pass a value of true for roundc - there's an example after the code:

Apply the border in the following way e.g....

regards,
Ben

ps:
Edited
mybutton.setBorder(new SubtleSquareButton(true));
to be
mybutton.setBorder(new SubtleSquareBorder(true));
Assumed this was a typo, Ben.
- satya

[This message has been edited by Madhav Lakkapragada (edited September 10, 2001).][/B]

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!