关于托动 JInternalFrame 没有虚线标记框的问题,急,在线等 你的JInternalFrame移动起来很慢么?我也用的JDesktopPane和JinternalFrame做的多文档窗口,移动速度很快呀。而且资源的消耗也不是很大。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我在JInternalFrame里用Graphics绘制了一些图形,如果只是单纯的移动几个位置,也没什么影响,但是如果托着来回绕,那CPU马上就到百分白了。很郁闷。所以想看看可不可以不让它重画里面的内容,最好的办法就是能够像JFrame那样只预先移动一个边框。等位置确定了在重画。 我觉得这个不是JInternalFrame的问题,你就是拖动一个资源管理器在屏幕上晃来晃去,CPU也会很高的。而且别人用程序估计也不会那样晃着看的。你看看代码中能不能减少重画的地方,如果不能减少,就这样吧。 在新的JDesktopPane desktopPane = new JDesktopPane()desktopPane.setDesktopManager(new OutlineManager());即可!class OutlineManager extends DefaultDesktopManager{ private Rectangle start, last; private boolean first = true; // dragging... public void beginDraggingFrame(JComponent frame) { initializeOutline(frame); } public void dragFrame(JComponent frame, int x, int y) { updateOutline(frame, x, y, start.width, start.height); } public void endDraggingFrame(JComponent frame) { endOutline(frame); } // resizing... public void beginResizingFrame(JComponent frame, int dir) { initializeOutline(frame); } public void resizeFrame(JComponent frame, int x, int y, int w, int h) { updateOutline(frame, x, y, w, h); } public void endResizingFrame(JComponent frame) { endOutline(frame); } // outline... private void initializeOutline(final JComponent frame) { frame.setVisible(false); start = frame.getBounds(); last = new Rectangle(start); first = true; SwingUtilities.invokeLater(new Runnable() { public void run() { updateOutline(frame, start.x, start.y, start.width, start.height); } }); } public void updateOutline(JComponent frame, int x, int y, int w, int h) { Container _container = frame.getParent(); Graphics g = _container.getGraphics(); try { g.setXORMode(_container.getBackground()); if (!first) { g.drawRect(last.x, last.y, last.width-1, last.height-1); } g.drawRect(x, y, w-1, h-1); first = false; } finally { g.dispose(); last.setBounds(x, y, w, h); } } public void endOutline(JComponent frame) { frame.setVisible(true); setBoundsForFrame( frame, last.x, last.y, last.width, last.height); }} Java Web Start 和 axis2 怎样通过名字获得类成员的reference? m$的J#是干什么用的?和传统的java的关系? JProgressBar在做启动画面载入时如何确定什么时候完事? 初学者的几个JAVA问题 如何编程读取PKCS#12格式的证书与私钥 java鼠标事件怎样区分左健和右健单击? 请问哪位有jcreator的注册码,高分相送 编译好的文件不能执行?急啊。。高分。 java问题2则(关于swing) 初学者请教:编写计算器程序中遇到的问题,50分求教! 求正则,为什么javascript可以通过,但java不能用呢?
JDesktopPane desktopPane = new JDesktopPane()
desktopPane.setDesktopManager(new OutlineManager());即可!class OutlineManager extends DefaultDesktopManager
{
private Rectangle start, last;
private boolean first = true; // dragging...
public void beginDraggingFrame(JComponent frame)
{
initializeOutline(frame);
} public void dragFrame(JComponent frame, int x, int y)
{
updateOutline(frame, x, y, start.width, start.height);
} public void endDraggingFrame(JComponent frame)
{
endOutline(frame);
} // resizing...
public void beginResizingFrame(JComponent frame, int dir)
{
initializeOutline(frame);
} public void resizeFrame(JComponent frame, int x, int y, int w, int h)
{
updateOutline(frame, x, y, w, h);
} public void endResizingFrame(JComponent frame)
{
endOutline(frame);
} // outline...
private void initializeOutline(final JComponent frame)
{
frame.setVisible(false);
start = frame.getBounds();
last = new Rectangle(start);
first = true; SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
updateOutline(frame, start.x, start.y, start.width, start.height);
}
});
} public void updateOutline(JComponent frame, int x, int y, int w, int h)
{
Container _container = frame.getParent();
Graphics g = _container.getGraphics(); try
{
g.setXORMode(_container.getBackground());
if (!first)
{
g.drawRect(last.x, last.y, last.width-1, last.height-1);
}
g.drawRect(x, y, w-1, h-1);
first = false;
}
finally
{
g.dispose();
last.setBounds(x, y, w, h);
}
} public void endOutline(JComponent frame)
{
frame.setVisible(true);
setBoundsForFrame(
frame, last.x, last.y, last.width, last.height);
}
}