JToolTip 内添加 Html 标记就可以换行了,你可以自己试试!一个JFrame的JAVA程序,其contentPane上add了许多JPanel,拖动窗口出屏幕以后拖回来,被覆盖的部分没有被重画,应该重载哪些方法,JFrame.paintComponents()???JFrame 拖动后会调用 paint() 函数,重绘窗口,但这是自动的啊!
如果你在 JFrame 里使用的 都是完整的(有自己的绘制功能)控件,它是会自己调用的,不用做任何的修改的.你的应该是代码本身出了问题,把代码贴出来看看就知道了.
如果你在 JFrame 里使用的 都是完整的(有自己的绘制功能)控件,它是会自己调用的,不用做任何的修改的.你的应该是代码本身出了问题,把代码贴出来看看就知道了.
解决方案 »
- 我想把字符串"white"转变成Color值
- soclet.setSoTimeout(10000)超时问题
- 如何使用exec调用media player 打开特定url
- 如何用链表表示一副扑克牌,我写的一段有明显错误,但我不会改,谢谢。
- 刚装好JCreater试试能不能用,结果编译不通过,不知道是不是安装问题,急等回答
- java hashset 生成随机数问题
- 一个JAVA的问题
- 不知道怎样写这个正则表达式???
- 有没有用JCreator开发JAVA的 ,有问题请教啊
- jar文件怎么运行啊!
- 220分,解決就全部送出!麻煩看看這個return問題...謝謝.
- -------正则匹配的问题-------
包含main()的文件package tri.dts.pf.monitor;import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class UserIconPool extends JPanel {
XYLayout xYLayout1 = new XYLayout(); Point firstIconPos = new Point(45,35);
boolean placeRandom = false;
int colCnt = 0;
int rowCnt = 0; public UserIconPool() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(xYLayout1);
this.setBackground(Color.cyan);
this.setBackground(MainDisp.USER_PANE_COLOR);
this.add(new UserIcon(80),new XYConstraints(80,80,0,0));
} public static void main(String[] argc) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocation(80,80);
UserIconPool userIconPool = new UserIconPool();
frame.setSize(600,600);
Container contentPane = frame.getContentPane();
contentPane.add(userIconPool,null);
frame.setVisible(true);
}
}相关文件UserIcon.java,我自己写的可拖动的一个对象
package tri.dts.pf.monitor;import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import java.text.NumberFormat;
import com.borland.jbcl.layout.*;
import javax.swing.ToolTipManager;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class UserIcon
extends JPanel {
int seq; int curMouseX;
int curMouseY;
UserIconPool parent;
JLabel jLabel1 = null;
TextLabel jLabel2 = null;
ImageIcon imageIcon1 = null;
BoxLayout2 boxLayout21 = new BoxLayout2();
String toolTipText = "<html>错误<br><font color='red'>没有设置正确的弹出信息</font></html>";
UserIcons userIcons = UserIcons.getInstance(); ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
public UserIcon(int seq) {
this.seq = seq;
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
} private void jbInit() {
toolTipManager.registerComponent(this);
this.setPreferredSize(new Dimension(100, 100));
this.setLayout(boxLayout21);
this.addMouseMotionListener(new this_Mouse_Motion_Adapter(this)); NumberFormat format = NumberFormat.getNumberInstance();
format.setMinimumIntegerDigits(3); imageIcon1 = userIcons.getUserIcon((int)Math.floor(Math.random()*10));
jLabel1 = new JLabel(imageIcon1);
jLabel2 = new TextLabel("用户"+format.format(seq),12,new Point(0,0));
jLabel2.setPreferredSize(new Dimension(45,15));
boxLayout21.setAxis(BoxLayout.PAGE_AXIS);
this.add(jLabel1, null);
jLabel1.setAlignmentX(Component.CENTER_ALIGNMENT);
this.add(jLabel2, null);
jLabel2.setAlignmentX(Component.CENTER_ALIGNMENT);
this.setPreferredSize(new Dimension(Math.max(imageIcon1.getIconWidth(),
jLabel2.getPreferredSize().
width),
imageIcon1.getIconHeight() +
jLabel2.getPreferredSize().height));
this.setToolTipText(toolTipText);
} public void mouseMovePerformed(MouseEvent e) {
curMouseX = e.getX();
curMouseY = e.getY();
} public void mouseDraggedPerformed(MouseEvent e) {
parent = (UserIconPool)getParent();
int newMouseX = e.getX();
int newMouseY = e.getY();
Point nextPoint = null;
Point newPoint = this.getLocation();
if ( (newMouseX + newPoint.x) > parent.getWidth() ||
(newMouseY + newPoint.y) > parent.getHeight() ||
(newMouseX + newPoint.x) < 0 ||
(newMouseY + newPoint.y) <0) {
return;
}
nextPoint = new Point(newPoint.x + (newMouseX - curMouseX),
newPoint.y + (newMouseY - curMouseY));
UserIconPool pool = (UserIconPool) getParent();
pool.remove(this);
pool.add(this, new XYConstraints(nextPoint.x, nextPoint.y, 0, 0));
this.revalidate();
repaint();
} public static void main(String[] argc) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(200, 200);
UserIcon userIcon = new UserIcon(5);
frame.getContentPane().add(userIcon);
frame.setVisible(true);
}
}class this_Mouse_Motion_Adapter
extends MouseMotionAdapter {
private UserIcon adaptee;
public this_Mouse_Motion_Adapter(UserIcon adaptee) {
this.adaptee = adaptee;
} public void mouseMoved(MouseEvent e) {
adaptee.mouseMovePerformed(e);
} public void mouseDragged(MouseEvent e) {
adaptee.mouseDraggedPerformed(e);
}
}
代码太长,你自己看看吧
应该不是机器慢吧?我知道程序有问题,我在找原因。
repaint()函数,去掉就没有问题了。但是不太清楚为什么。