• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What Draws This Title Bar?

 
Stevens Miller
Bartender
Posts: 1377
28
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created an undecorated JFrame and set it to ignore system-generated repaint events. At run-time, nothing appears on my desktop (as I expected) and an icon appears in the taskbar (as I also expected). If I click on the icon, nothing changes on the desktop (as the invisible window is iconified). When I click on the icon again, a small title bar appears on the desktop. It's not responsive to mouse-clicks. I can make it come and go with clicks on the icon.

Here's my code:



When I click on the icon, then click again, this appears on my desktop:



Interestingly, when I use Alt/PrtSc to do the screencap, I get this:



Which says that Windows (my OS) knows the size of the window as it was set in my code. (Nothing surprising about that, I guess.)

Subclassing JFrame and overriding its paint method proves that paint is never called.

So what is drawing the title bar?
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is drawing the title bar?


The frame is a component of the underlying OS.

So the title bar and borders are painted by Windows in your case.

Components you add to the frame are painted by Swing.
 
Stevens Miller
Bartender
Posts: 1377
28
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:The frame is a component of the underlying OS.
So the title bar and borders are painted by Windows in your case.

Then why doesn't the title bar appear when the JFrame is first made visible?
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what the problem is. I have never used setIgnoreRepaint(true) before.

I have used setUndecorated(true) before and the frame paint correctly without the title bar.
 
Stevens Miller
Bartender
Posts: 1377
28
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:I have used setUndecorated(true) before and the frame paint correctly without the title bar.

That seems to be because the title bar I am seeing is actually inside the client area of the window. It's not where the title bar would be if I left the window decorated. Thus, if you paint the client area, you obliterate this particular title bar (and, therefore, never see it).

It's very strange because, in addition to all of the foregoing, it's not even in the normal style of a Windows 10 title bar. It looks like a Windows XP title bar.

Does anyone think this qualifies as a reportable bug in Java?
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Windows 7 I just get a black rectangular box painted.

Is it a bug? Well I would say the method is being used in a way it was not intended to be used and you get the inconsistency.

Swing has a contract to repaint the client area to make sure there is no garbage in the client area. Since you are not responding to events I guess there is garbage left in this client area.

I added a JButton to the BorderLayout.SOUTH of the frame and the problem when away. I then replaced the JButton with a JLabel to the BorderLayout.SOUTH and the problem remained. I guess the difference is that a JButton would receive focus and the focus border needs to be painted so Swing would generated the paint request and the entire client area is painted.

So the frame is originally displayed correctly because a Swing repaint() would be invoked when the frame is made visible. However, the minimize/restore events are OS level events so it appears the Swing repaint() is not being invoked, which is reasonable since you disabled this property.
 
Stevens Miller
Bartender
Posts: 1377
28
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Is it a bug? Well I would say the method is being used in a way it was not intended to be used and you get the inconsistency.

Swing has a contract to repaint the client area to make sure there is no garbage in the client area. Since you are not responding to events I guess there is garbage left in this client area.

That sounds reasonable. I may be looking at UB, and just not knowing it.

Interestingly, if you use the same code on a plain old Frame (rather than a JFrame), it does paint the client area (white, in my case):



Also somewhat interestingly, if the window overlaps another one, I do still see that title bar briefly when I un-iconify the running program, but it is immediately overpainted with the white client area.

In actual practice, this won't be much of a problem, as I discovered this while experimenting with active rendering. In my real application, I'll overwrite the entire client area myself, thus meeting the contract terms on my own. It's just interesting to see that, after I do everything I can to avoid anything being drawn in the client area that I don't put there myself, something still shows up.
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interestingly, if you use the same code on a plain old Frame (rather than a JFrame)...


AWT uses the platform components to display the GUI. That is why AWT will always look like the platform you run on.

Swing does custom painting of all the components to look like the platform, which is why you have more control over the look and feel of Swing components.

These are referred to as "heavyweight" and "lightweight" components. See the article on Mixing Heavyweidht and Lightweight Components.
 
Stevens Miller
Bartender
Posts: 1377
28
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Swing does custom painting of all the components to look like the platform, which is why you have more control over the look and feel of Swing components.

These are referred to as "heavyweight" and "lightweight" components. See the article on Mixing Heavyweidht and Lightweight Components.


I actually knew all that, but thanks. What I'm trying to get a grip on is why that title bar ever appears. It seems that it is the OS (Windows) drawing it, but there's no obvious reason why Windows would do that. Even from Windows's perspective, that's in the client area where a title bar has no business ever being. Then again, if it's something specific to Java, the same logic applies: there's no reason for that title bar ever to be there, even if (contractually or otherwise) it gets overpainted. The fact that, in all these contexts, that area is virtually always overpainted (and, therefore, one would typically not ever see that title bar) doesn't change the fact that it seems to serve no useful purpose ever being drawn there. It has overhead for no reason.

Very puzzling.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic