java程序去除系统窗体,如何从任何java gui中删除窗口框

How do i remove the window box from any java program. Because i want to make it look border-less. I know any jar files running on jre automatically gets a window like this. So i want to know if there is workaround about this.

Thanks in advance

here is a photo what i want to do exactly

MiCSf.png

解决方案

You could also use a JWindow which is undecorated by default.

Check this and this for example uses

Updated

If you remove the border, you become responsible for moving and resizing of the window...

This "basic" example demonstrates how to move a JWindow with the mouse. This makes a "drag zone" around window which is 10 pixels wide.

Resizing would be similar process, but you need to decide in which direction to resize (ie it might need you to move the window when it's resized ;))

import java.awt.Component;

import java.awt.Cursor;

import java.awt.EventQueue;

import java.awt.Point;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.JWindow;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

public class TestMoveWindow {

public static void main(String[] args) {

new TestMoveWindow();

}

public TestMoveWindow() {

EventQueue.invokeLater(new Runnable() {

@Override

public void run() {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {

}

JWindow window = new JWindow();

window.setSize(200, 200);

window.addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

MouseAdapter mouseHandler = new MouseAdapter() {

private Point offset;

protected boolean isWithinBorder(MouseEvent e) {

Point p = e.getPoint();

Component comp = e.getComponent();

return p.x < 10 || p.y < 10 || p.x > comp.getWidth() - 10 || p.y > comp.getHeight() - 10;

}

@Override

public void mouseMoved(MouseEvent e) {

Component comp = e.getComponent();

if (isWithinBorder(e)) {

System.out.println("Move");

comp.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));

} else {

System.out.println("Default");

comp.setCursor(Cursor.getDefaultCursor());

}

}

@Override

public void mouseDragged(MouseEvent e) {

if (offset != null) {

Point pos = e.getLocationOnScreen();

int x = pos.x - offset.x;

int y = pos.y - offset.y;

System.out.println(x + "x" + y);

SwingUtilities.getWindowAncestor(e.getComponent()).setLocation(x, y);

}

}

@Override

public void mousePressed(MouseEvent e) {

if (isWithinBorder(e)) {

Point pos = e.getComponent().getLocationOnScreen();

offset = new Point(e.getLocationOnScreen());

offset.x -= pos.x;

offset.y -= pos.y;

}

}

};

window.getContentPane().addMouseListener(mouseHandler);

window.getContentPane().addMouseMotionListener(mouseHandler);

window.setLocationRelativeTo(null);

window.setVisible(true);

}

});

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值