PDA

View Full Version : Swing



hossein71
شنبه 04 شهریور 1391, 12:02 عصر
سلام
آیا میشه در JPanel گوشه ها رو گرد کرد؟

hossein71
سه شنبه 07 شهریور 1391, 17:58 عصر
جناب ابولفضل نمیدونم چرا پاسختون رو بصورت خصوصی فرستادید.درهرحال خیلی ممنون ولی این روش دوتا مشکل داره:
1-من میخوام گوشه ها بصورت نیم دایره و نرم گرد بشه ولی حالت برشی به گوشه ها میده
2-انگار دوتا لایه ایجاد میشه یکی گوشه هاش صاف هست دیگری بریده شده و این دوتا روی هم قرار میگیرن


import javax.swing.border.Border;
import java.awt.*;
public class SubtleSquareBorder implements Border{

protected int m_w = 10;
protected int m_h = 10;
protected Color m_topColor = Color.white;
protected Color m_bottomColor = Color.gray;
protected boolean roundc = false;
public SubtleSquareBorder(boolean round_corners)
{
roundc = round_corners;
}

@Override
public Insets getBorderInsets(Component c) {
return new Insets(m_h, m_w, m_h, m_w);
}

@Override
public boolean isBorderOpaque() {
return true;
}

@Override
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
w = w - 3;
h = h - 3;
x ++;
y ++;
// Rounded corners
if(roundc)
{
g.setColor(null);
g.drawLine(x, y + 10, x, y + h - 10);
g.drawLine(x + 10, y, x + w - 10, y);
g.drawLine(x, y + 10, x + 10, y); // Top left diagonal
g.drawLine(x, y + h - 10, x + 10, y + h); // Bottom left diagonal
g.setColor(null);
g.drawLine(x + w, y + 10, x + w, y + h - 10);
g.drawLine(x + 10, y + h, x + w -10, y + h);
g.drawLine(x + w - 10, y, x + w, y+10 ); // Top right diagonal
g.drawLine(x + w, y + h - 10, x + w -10, y + h); // Bottom right diagonal
}
// Square corners
else
{
g.setColor(m_topColor);
g.drawLine(x, y, x, y + h);
g.drawLine(x, y, x + w, y);
g.setColor(m_bottomColor);
g.drawLine(x + w, y, x + w, y + h);
g.drawLine(x, y + h, x + w, y + h);
}
}
}

hossein71
پنج شنبه 09 شهریور 1391, 07:49 صبح
کسی جواب نمیده یعنی این کار شدنی نیست؟

hossein71
دوشنبه 20 شهریور 1391, 16:16 عصر
یعنی واقعا نمیشه در جاوا گوشه های jpanel رو گرد کرد یا jpanel دایره ای ساخت؟

yegane8
دوشنبه 20 شهریور 1391, 17:08 عصر
http://docs.oracle.com/javase/tutorial/uiswing/components/border.html
http://www.codeproject.com/Articles/114959/Rounded-Border-JPanel-JPanel-graphics-improvements