Results 1 to 9 of 9
Thread: remove close button
- 05-29-2010, 03:57 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 72
- Rep Power
- 0
- 05-29-2010, 04:30 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
You can't remove it but you can make it unresponsive by using:
Java Code:dialog.setDefaultCloseOperation( JDialog.DO_NOTHING_ON_CLOSE );
- 05-29-2010, 07:12 PM #3
Member
- Join Date
- Jan 2010
- Posts
- 72
- Rep Power
- 0
i read on a thread that the way to do this is to remove the title bar and adding your own title bar
now the whole title bar can be removed by
but i dont know how to set my own title barJava Code:setUndecorated(true)
i also tried the following code
but nothing worked outJava Code:public static void removeCloseButton(Component comp) { if (comp instanceof JMenu) { Component[] children = ((JMenu) comp).getMenuComponents(); for (int i = 0; i < children.length; ++i) removeCloseButton(children[i]); } else if (comp instanceof AbstractButton) { Action action = ((AbstractButton) comp).getAction(); String cmd = (action == null) ? "" : action.toString(); if (cmd.contains("CloseAction")) { comp.getParent().remove(comp); } } else if (comp instanceof Container) { Component[] children = ((Container) comp).getComponents(); for (int i = 0; i < children.length; ++i) removeCloseButton(children[i]); } }Last edited by silversurfer2in; 05-29-2010 at 07:14 PM.
- 05-30-2010, 12:10 AM #4
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
to remove the X you firstly need to set java's L&F
JDialog.setDefaultLookAndFeelDecorated(true);
setting it 'before' the dialog is created.
then your removeCloseButton(..) works OK,
but java's L&F isn't overly popular
- 05-30-2010, 09:32 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 72
- Rep Power
- 0
I tried it but its not working...
i am creating JDialog in a mouse listener event
my code goes like this
please check this and tell meJava Code:MouseListener mouseListener = new MouseAdapter() { JDialog d = new JDialog(frame, "Human Resource"); public void mouseEntered(MouseEvent me) { JDialog.setDefaultLookAndFeelDecorated(true); d.setSize(200,200); d.setLocation(me.getX(),me.getY()); d.setVisible(true); removeCloseButton(d); } public void mouseExited(MouseEvent me) { d.setVisible(false); } }; public static void removeCloseButton(Component comp) { if (comp instanceof JMenu) { Component[] children = ((JMenu) comp).getMenuComponents(); for (int i = 0; i < children.length; ++i) removeCloseButton(children[i]); } else if (comp instanceof AbstractButton) { Action action = ((AbstractButton) comp).getAction(); String cmd = (action == null) ? "" : action.toString(); if (cmd.contains("CloseAction")) { comp.getParent().remove(comp); } } else if (comp instanceof Container) { Component[] children = ((Container) comp).getComponents(); for (int i = 0; i < children.length; ++i) removeCloseButton(children[i]); } }
- 05-30-2010, 12:10 PM #6
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
> I tried it but its not working...
You didn't try it correctly.
noted previously:
"setting it 'before' the dialog is created."
in your code you create the dialog in the class,
then you set the default L&F in mouseEntered
- 05-30-2010, 05:46 PM #7
Member
- Join Date
- Jan 2010
- Posts
- 72
- Rep Power
- 0
what should be the look and feel... i have changed it to window feel
rest is same...and still its not working...please tell me...i will be very gratefulJava Code:try { // Set L&F to window UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (UnsupportedLookAndFeelException e) { // handle exception } catch (ClassNotFoundException e) { // handle exception } catch (InstantiationException e) { // handle exception } catch (IllegalAccessException e) { // handle exception }Last edited by silversurfer2in; 05-30-2010 at 05:52 PM.
- 05-30-2010, 09:44 PM #8
Member
- Join Date
- Jul 2008
- Posts
- 62
- Rep Power
- 0
here's a working example
do NOT add any additional code to it, just copy/paste/compile/run,
and see that it removes the 'X', then play around with it.
Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing { public void buildGUI() { JDialog.setDefaultLookAndFeelDecorated(true); JDialog d = new JDialog(); d.setModal(true); removeCloseButton(d); JPanel p = new JPanel(new GridBagLayout()); JButton btn = new JButton("Exit"); p.add(btn,new GridBagConstraints()); d.getContentPane().add(p); d.setSize(400,300); d.setLocationRelativeTo(null); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ System.exit(0); } }); d.setVisible(true); } public void removeCloseButton(Component comp) { if (comp instanceof JMenu) { Component[] children = ((JMenu) comp).getMenuComponents(); for (int i = 0; i < children.length; ++i) removeCloseButton(children[i]); } else if (comp instanceof AbstractButton) { Action action = ((AbstractButton) comp).getAction(); String cmd = (action == null) ? "" : action.toString(); if (cmd.contains("CloseAction")) { comp.getParent().remove(comp); } } else if (comp instanceof Container) { Component[] children = ((Container) comp).getComponents(); for (int i = 0; i < children.length; ++i) removeCloseButton(children[i]); } } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run(){ new Testing().buildGUI(); } }); } }
- 05-31-2010, 10:53 AM #9
Member
- Join Date
- Jan 2010
- Posts
- 72
- Rep Power
- 0
Similar Threads
-
Minimize (not exit) the application to tray when the close button is clicked
By Nandish Reddy in forum EclipseReplies: 0Last Post: 04-28-2010, 01:39 PM -
Will the connection.close() and statement.close() ever be called???
By Stephen Douglas in forum New To JavaReplies: 13Last Post: 04-09-2010, 11:15 AM -
How do I close a frame with a button?
By Psyclone in forum AWT / SwingReplies: 7Last Post: 02-19-2010, 10:43 PM -
Button to remove item from list
By dacool25 in forum Java AppletsReplies: 6Last Post: 10-14-2009, 04:30 AM -
how disable the display of close button on the frame
By kalanidhi in forum New To JavaReplies: 6Last Post: 11-19-2008, 09:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks