急求用swing实现不规则窗体 请问如何用swing实现不规则窗体,比如画一个房子,或者一艘船之类的。查了一下JDK6.0新增了不透明和不规则窗口的功能,但是还是没有弄明白,请教各位大侠帮忙! 小弟感激不尽,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【vinoya】截止到2008-07-10 21:56:12的历史汇总数据(不包括此帖):发帖的总数量:2 发帖的总分数:40 每贴平均分数:20 回帖的总数量:11 得分贴总数量:3 回帖的得分率:27% 结贴的总数量:2 结贴的总分数:40 无满意结贴数:0 无满意结贴分:0 未结的帖子数:0 未结的总分数:0 结贴的百分比:100.00% 结分的百分比:100.00% 无满意结贴率:0.00 % 无满意结分率:0.00 % 敬礼! JDK6没有,j2se6 update N有还未发布的JDK7有要用的话去搜一下,有现成的第三方包的 JNI可以实现。我见过这种方法的效果。用JNI和Windows API中的SetWindowRgn函数作的 比如百度、google、sohu之类的,哈哈~~~~~~~~~~~~~~~~ SWT倒是可以实现楼主的要求。可惜不是Swing了 - -/*************************************************************************************************** * Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This program and the * accompanying materials are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: IBM Corporation - initial API and implementation **************************************************************************************************/package org.eclipse.swt.snippets;import org.eclipse.swt.*;import org.eclipse.swt.graphics.*;import org.eclipse.swt.widgets.*;/** * Region snippet: Create non-rectangular shell from an image with transparency * * For a list of all SWT example snippets see http://www.eclipse.org/swt/snippets/ * * @since 3.2 */public class Snippet219{ public static void main( String[] args ) { final Display display = new Display(); final Image image = display.getSystemImage( SWT.ICON_INFORMATION ); final Shell shell = new Shell( display, SWT.NO_TRIM ); Region region = new Region(); final ImageData imageData = image.getImageData(); if( imageData.alphaData != null ) { Rectangle pixel = new Rectangle( 0, 0, 1, 1 ); for( int y = 0; y < imageData.height; y++ ) { for( int x = 0; x < imageData.width; x++ ) { if( imageData.getAlpha( x, y ) == 255 ) { pixel.x = imageData.x + x; pixel.y = imageData.y + y; region.add( pixel ); } } } } else { ImageData mask = imageData.getTransparencyMask(); Rectangle pixel = new Rectangle( 0, 0, 1, 1 ); for( int y = 0; y < mask.height; y++ ) { for( int x = 0; x < mask.width; x++ ) { if( mask.getPixel( x, y ) != 0 ) { pixel.x = imageData.x + x; pixel.y = imageData.y + y; region.add( pixel ); } } } } shell.setRegion( region ); Listener l = new Listener() { int startX, startY; public void handleEvent( Event e ) { if( e.type == SWT.KeyDown && e.character == SWT.ESC ) { shell.dispose(); } if( e.type == SWT.MouseDown && e.button == 1 ) { startX = e.x; startY = e.y; } if( e.type == SWT.MouseMove && ( e.stateMask & SWT.BUTTON1 ) != 0 ) { Point p = shell.toDisplay( e.x, e.y ); p.x -= startX; p.y -= startY; shell.setLocation( p ); } if( e.type == SWT.Paint ) { e.gc.drawImage( image, imageData.x, imageData.y ); } } }; shell.addListener( SWT.KeyDown, l ); shell.addListener( SWT.MouseDown, l ); shell.addListener( SWT.MouseMove, l ); shell.addListener( SWT.Paint, l ); shell.setSize( imageData.x + imageData.width, imageData.y + imageData.height ); shell.open(); while( !shell.isDisposed() ) { if( !display.readAndDispatch() ) display.sleep(); } region.dispose(); image.dispose(); display.dispose(); }} 第三方包JNA可以,主页地址https://jna.dev.java.net/用法 RoundRectangle2D.Float mask = new RoundRectangle2D.Float(0, 0, jframe.getWidth(), jframe.getHeight(), 10, 10); WindowUtils.setWindowMask(jframe, mask); java代码编译报错,请高手帮哈忙 求助,出现了错误 很紧急...请来帮忙帮忙 关于Java Web Start部署 SWT 应用程序的问题 请问JAVA中有没有不规则形状的PANEL 急~~~~~~~~~~ JAVA中有没有类似于vc中的AfxMessageBox()的提示窗口??? 用JBUILDER6,Applet做数据库查询,为什么IE看不见? Javareg用后出现的问题 问几个基础问题 谢谢~ swing布局的问题,怎么才能让组件紧凑些 Thread.yield()的问题
楼主【vinoya】截止到2008-07-10 21:56:12的历史汇总数据(不包括此帖):
发帖的总数量:2 发帖的总分数:40 每贴平均分数:20
回帖的总数量:11 得分贴总数量:3 回帖的得分率:27%
结贴的总数量:2 结贴的总分数:40
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满意结贴率:0.00 % 无满意结分率:0.00 %
敬礼!
还未发布的JDK7有
要用的话去搜一下,有现成的第三方包的
比如百度、google、sohu之类的,哈哈~~~~~~~~~~~~~~~~
/***************************************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This program and the
* accompanying materials are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors: IBM Corporation - initial API and implementation
**************************************************************************************************/
package org.eclipse.swt.snippets;import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;/**
* Region snippet: Create non-rectangular shell from an image with transparency
*
* For a list of all SWT example snippets see http://www.eclipse.org/swt/snippets/
*
* @since 3.2
*/
public class Snippet219
{
public static void main( String[] args )
{ final Display display = new Display();
final Image image = display.getSystemImage( SWT.ICON_INFORMATION );
final Shell shell = new Shell( display, SWT.NO_TRIM );
Region region = new Region();
final ImageData imageData = image.getImageData();
if( imageData.alphaData != null )
{
Rectangle pixel = new Rectangle( 0, 0, 1, 1 );
for( int y = 0; y < imageData.height; y++ )
{
for( int x = 0; x < imageData.width; x++ )
{
if( imageData.getAlpha( x, y ) == 255 )
{
pixel.x = imageData.x + x;
pixel.y = imageData.y + y;
region.add( pixel );
}
}
}
} else
{
ImageData mask = imageData.getTransparencyMask();
Rectangle pixel = new Rectangle( 0, 0, 1, 1 );
for( int y = 0; y < mask.height; y++ )
{
for( int x = 0; x < mask.width; x++ )
{
if( mask.getPixel( x, y ) != 0 )
{
pixel.x = imageData.x + x;
pixel.y = imageData.y + y;
region.add( pixel );
}
}
}
}
shell.setRegion( region ); Listener l = new Listener()
{
int startX, startY;
public void handleEvent( Event e )
{ if( e.type == SWT.KeyDown && e.character == SWT.ESC )
{
shell.dispose();
}
if( e.type == SWT.MouseDown && e.button == 1 )
{
startX = e.x;
startY = e.y;
}
if( e.type == SWT.MouseMove && ( e.stateMask & SWT.BUTTON1 ) != 0 )
{
Point p = shell.toDisplay( e.x, e.y );
p.x -= startX;
p.y -= startY;
shell.setLocation( p );
}
if( e.type == SWT.Paint )
{
e.gc.drawImage( image, imageData.x, imageData.y );
}
}
};
shell.addListener( SWT.KeyDown, l );
shell.addListener( SWT.MouseDown, l );
shell.addListener( SWT.MouseMove, l );
shell.addListener( SWT.Paint, l ); shell.setSize( imageData.x + imageData.width, imageData.y + imageData.height );
shell.open();
while( !shell.isDisposed() )
{
if( !display.readAndDispatch() )
display.sleep();
}
region.dispose();
image.dispose();
display.dispose();
}
}
RoundRectangle2D.Float mask = new RoundRectangle2D.Float(0, 0, jframe.getWidth(), jframe.getHeight(), 10, 10);
WindowUtils.setWindowMask(jframe, mask);