Is it possible to customize main JFrame title rendering in Swing? - java

I'd like to customize the title of my main JFrame on a Swing application.
There's two things I'd like to do, but can't find any way to achieve it :
use an Image to put behind the title of the main JFrame. Something like this :
http://www.hostingpics.net/viewer.php?id=521357Untitled.png
use a GradientPaint (or similar "tweak") to put a gradient color behind the title of the JFrame. Something like this :
http://www.hostingpics.net/viewer.php?id=842390Untitled2.png
Is there any way to do that easily in Swing ?
Thanks,

You cannot modify system native frames/dialogs decorations (including frame/dialog title).
Though there are two ways to modify the whole frame/dialog decoration:
You have to use some specific L&F in your application that has custom frame/dialog decorations and allows to change it - i don't really know if there is such. (you can find many L&Fs that have their own frame/dialog decorations, for example this one)
You have to install your own RootPaneUI that will customize frame decoradion, but be aware that you will have to write all of the frame/dialog decoration features on your own (including window drag and resize, control buttons, title and others) - that requires a good knowledge of UIs, graphics and Swing.

Another way (I used in Delphy some years ago...):
Don't display the default title bar, and put your own on one (made with all you want :p), and reimplement all the behaviaviour (drag n drop, maximize, minimize,...).

Related

Java Swing: how to shade a game gui after the match has finished

In a board game we are developping in Java we would like the gui to be overshadowed when the game is finished. We have a Jframe in which there is JPanel with the board on which there are some colored pawns and boxes (JButtons) and we would like that everything becomes a sort of black and white and grey. Is there an authomatic method in Java to do this in Java Components?
There are several different kinds of panes to look at that could achieve this, or something similar, if you are using Swing (which I assume from the tag, that you are).
You could use a Glass Pane. http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html#glasspane
glass panes could be thought of as like a CSS overlay. They dis-allow interaction with components behind them.
Also, take a look at JXLayers and JLayers, they allow you to modify the way components are actually painted.
Good Luck!
Override paintComponent() (Or if you have some components added to the container it's better to override paintComponents() method).
Call
super.paintComponent(g);
Color semiColor=new Color(0,0,0,128);//the last param represents alpha
g.fillRect(semiColor);

JAVA: How can I add SWING components to my game HUD with custom textures

-- Little note, I attempted to upload an image of my game to illustrate my question, however I do not yet have the required reputation to do so. I apollogise for this.
I would like to create a drop down screen from the top HUD element on my game which the player can type into, effectively becoming a chat window, the actually window is not an issue and I understand that you can disable background and boarder rendering of Java's Swing components so that isn't an issue.
My question is simple, can I take advantage of java's Swing components like JTextField and position them exactly within the bounds of this area, without having to deal with java's layout classes. So this is a summary:
How do I set the final size of the swing components MANUALLY and
How do I set coordinates of the components MANUALLY With out using a layout manager
Yes you can use a null layout on the container and call setBounds(...) on the component to MANUALLY place them. And this is usually a VERY BAD THING to do as it forces you to paint yourself into a layout corner making it very hard to upgrade or enhance your GUI later. It also guarantees that your GUI will look terrible on all platforms and screen resolutions other than one. Many newbies usually go this route initially, and then most leave it eventually after gaining more experience with Swing as they run into its failings, weaknesses and limitations.
For a more complete answer, consider giving more specifics and in image (we can help with this) of your GUI layout requirements.

Graphics and applets

I am currently working on an assignment and need to create basic controls (buttons) for the Mandelbrot set that will operate as a JApplet. The graphics is initialised in the init() method and a method which draws the Mandelbrot is called in start(). The problem is, I have searched high and low and cannot figure out how to add a GUI to my applet because
I don't explicitly add the mandelbrot to a JPanel , and..
I have no room left it seems to add a GUI because the Mandelbrot takes up the entire JFrame.
I had one idea which was to set the size of the JFrame, set the size of the Mandelbrot graphic to only be say 4/5 of the whole frame, and add buttons to the remaining portion?
Does that sound like a good solution?
Does that sound like a good solution?
No. The panel in which the Mandelbrot is drawn should return a sensible preferred size. Add the rendering panel and the buttons to a layout or groups of layouts using layout padding, borders and button margins for white space.
But I am a little confused by the reference to japplet tag yet the body of the question mentions both JApplet and (twice) JFrame.
An applet has to make do with whatever size it is provided by the HTML (or JS, in the case of the deployment toolkit script) that launches it.
A frame can call pack() on a properly laid out UI and expect to be the smallest size needed to display the components.
General tips
Why code an applet? If it is due to spec. by teacher, please refer them to Why CS teachers should stop teaching Java applets.
For deploying Java desktop apps., the best option is usually to install the app. using Java Web Start. JWS allows the user to launch a JFrame from a link in a web page.
Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them1, along with layout padding & borders for white space2.

Recommended JScrollPane navigation widget

Can anyone recommend a decent Swing widget for navigating JScrollPanes? I refer to the type of navigation window you often see in CAD applications that allow you to reposition the viewport by dragging the position of small box (the view port) within a larger box (the underlying component).
To date I've found this, but wondered if there was anything else out there, perhaps as part of a UI library?
Ideally I would also like to render a scaled version of the component in the navigation window.
EDIT
To address some of mKorbel's questions:
The application I'm developing is Swing-based.
The component within the JScrollPane is a JPanel for which I've overridden the paintComponent method in order to draw shapes using Java 2D.
Hence I'm effectively mixing Java 2D and Swing.
Swinglabs incubator has a JXScrollMap, a candidate for future addition. It's in Karl Schaefer's section under scrollmap (he's restructuring, so not entirely sure how stable that latter link is).

Java Applet to Multi Panel Application

I have made a Java game, but it is applet based. I want to convert it into a standalone application. Unfortunately I have 0 knowledge of swing/java applications so I'm not exactly sure where to start and how to get what I want.
My main issue is that the game screen is essentially divided into two parts. The "game screen" and what I refer to as the "dashboard". If you can imagine age of empires, star craft, or any other RTS type of game, that's what the layout is.
So what I want is the screen to have its own graphics panel (all the drawing/animation is done with the graphics and image class) that also has scroll bars in it, that way the size of the game isn't limited to the size of your screen. And I want the dashboard to be it's own separate independent panel, which also uses graphics methods. But in the end, both panels are in the same window.
Is there anyway this is possible?
PS: feel free to request any code or screenshots of the game
Edit: if it is possible, how should I go about doing this?
Simple Swing applications usually based on JFrame class. As i understand, whole game is rendered and not using standard components in UI. Then, roughly, almost no difference between JApplet and JFrame classes. If you used specific JApplet methods for loading resources or something similar, almost all of them would easily replaced with counterparts.
You could create a component class (by extending JComponent) and use it to render main game window. And create another one to render dashboard. Then use BorderLayout as layout manager on JFrame, place main window on center and dashboard on any edge.
There are pretty clear HowTo`s on Oracle site:
How to Make Frames and How to Use Panels.
I think Mersenne's answer covers it pretty well, though I'd consider rendering the game play in a BufferedImage and adding that to (an ImageIcon in) a JLabel in a JScrollPane.

Categories

Resources