3

I'm trying to allow the user to change the title of a window in Java without adding components to the window itself. I'm actually trying this with a JInternalFrame, but figure the solution should be similar for a JFrame. I simply want to add an additional menu item in the context menu that pops up when right clicking on a window title bar. For example, the Set title below:

enter image description here

This example is on Windows XP, but perhaps there's a way to get the window context menu OS independently perhaps similar to the SystemTray.getSystemTray() (but for individual windows within an application). From this I would be able to provide my own ActionListener to popup a dialog for the user to enter a new title.

Is this a much bigger task than I'm guessing it is? Does anyone have solutions they've used before?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
E-rich
  • 9,243
  • 11
  • 48
  • 79
  • 1
    this funcionaliality comings for Native OS, you have to overode WindowsListener, change DefalutCloseOperation.NOTHING_ON_CLOSE and create JDialog with Custom JMenu and JMenuItes, place this JDialog to the left-top windows container on Window' Close event – mKorbel Jun 20 '11 at 16:44

2 Answers2

2

Short answer: I don't think this is easy. I'm not 100% sure if it is possible.

First, JFrame and JInternalFrame are actually quite different. JFrame is a top level component whose title bar and such are typically provided by the OS. JInternalFrame's entire content (including title bar) is provided by the Swing LAF.

For a JInternalFrame, the context menu is provided by the LAF, not JInternalFrame itself. You would have to do something with the UIComponent in order to change the context menu. I think you would likely have to provide a custom UI component in order to do this, which is ugly and typically breaks across different LAFs or works but looks terrible at best. See BasicInternalFrameTitlePane, the createSystemMenu method.

wolfcastle
  • 5,850
  • 3
  • 33
  • 46
  • +1 That's basically what I meant with 'digging too deep'. Thanks for elaborating :) – vehk Jun 20 '11 at 17:00
1

I don't think this is possible without digging way too deep into Swing's internal UI system and I wouldn't even consider doing this. Why don't you use the inbuilt JMenuBar of JInternalFrame?

myInternalFrame.setJMenuBar(myMenuBar);
vehk
  • 926
  • 7
  • 7