Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to give drag functionaly to a JFame with no titleBar?

i m creating a JFrame with four buttons in its titleBar.

JFrame frame=new JFrame("custom JFrame with 4 buttons in title");
frame.setUndecorated(true);

JPanel button_panel=new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton button_1=new JButton("+");
JButton button_2=new JButton("↑");
JButton button_3=new JButton("-");
JButton button_4=new JButton("system tray");

button_panel.add(button_1);
button_panel.add(button_2);
button_panel.add(button_3);
button_panel.add(button_4);

frame.getContentPane().add(button_panel,BorderLayout.NORTH);

now, i have a JFrame with four buttons in its titlebar.

but, how to give drag functionality to this custom JFrame?

like image 531
Lokesh Kumar Avatar asked Jan 20 '23 02:01

Lokesh Kumar


1 Answers

is it the only solution?

Well, the only solution that I know of is to use MouseListeners.

For a more general solution you can check out Moving Windows which allows you to make any Swing component dragable.

like image 147
camickr Avatar answered Jan 29 '23 20:01

camickr