jframe

Save JFrame location in multi-display environment

I want to store a JFrame's location (bounds, extendedState) when the user closes it. However, when the user moves the frame onto the 2nd screen and maximizes it, how can I store that information? My naive (and single display) implementation is like this: void saveFrame(JFrame frame) throws IOException { Properties props = new Prope...

How to use something other than the DefaultClosingOperation when closing a JFrame window?

Hi, I am working on a chat client using a socket, and I want a certain code to be executed before the window closes when the user clicks on "X" (like closing the connection properly). Can I do that without having to implement all the abstract methods in WindowListener? /Avin ...

How to display html in a java application?

Hi, Now I am working on implementing a browser in Java. I need to display the contents of a website (provided a url-address) inside a JFrame window. Is there a simple way of doing that? I tried JEditorPane, but it only supports HTML 3.2, so the contents of the website looks very weird. Thanks ...

Controlling JFrame from JMenuBar

I am trying to maximize JFrame from within JMenuBar, I can not pass a reference to the frame. Is it possible to get a reference to the frame that it is used in? i can get to the top level component but it does not have a way to maximize and minimize frame. public Container getApplicationFrame(ActionEvent event){ JMenuIte...

JFrame in Java

Hi, I am using a JFrame as a pop-up from a main frame, where the user is supposed to enter some information and then press OK. But the problem is that once this sub-frame has opened up, I want the program to ignore any other signal until the OK button is pressed, similar as how it is done with JOptionPanes. As it is now, you could click ...

Showing Japanese Characters in TItle Bar of Java Program

I am able to display Japanese characters everywhere except for the title bar of the main window (JFrame) in Java. Is there a way to change the font of this title bar so it can display japanese characters? Thanks I am using Windows XP. If this matters I am using the Java Substance look and feel too. ...

(Java) Appearing/Disappearing JLabel in a JPanel only disappears on resize

I'm working in Java, and I have a JPanel in a JFrame. In that JPanel, among other things, I have a JLabel that I want to make appear and disappear at will. I've tried setting visibility to true/false, adding and removing it from the JFrame and JPanel, and, having looked online, I tried validate()ing and revalidate()ing ad infinitum. What...

Edit an image in java

hello, I have an image a map, The image must be contained in a JFrame and asked whether there are any java method that given coordinates (x, y) must make a kind of water mark or repaint the picture only in the specified coordinate anyone knows how to do or any idea how it would try to do ?? ...

How to make Jpanel expand to the size of the JFrame?

The below code is from the book objects First With Java By Michale Kolling and David J Barnes and the following is an exercise (ex 5.49) from the book.The ex is : Improve your drawFrame method to adapt automatically to the current canvas's size.To do this you need to find out how to make use of an objectof class Dimension. In the follow...

Floating Rectangle on Screen

I know how to draw a rectangle onto a JPanel, but how can I paint a rectangle to the screen so that the rectangle appears to be floating? More specifically, a non-filled rectangle. My thought is to use a transparent JFrame with a rectangle drawn on it; however, this makes all of the content in the JFrame transparent. My Solution S...

Embedding a JPanel in a Frame

I created a Java application in NetBeans which consists of a bunch of components on a JPanel. I know want to embed this application on a frame which will be a completely separate application. I can't seem to be able to do this...any suggestions? ...

How do I start optimising my Java code? - CPU is at 100%

i have written an application, but for some reason it keeps peaking at 100%. I ran a profile r on a few of the classes and a report show that isReset() and isRunning() seems to be called alot of times. Do you see anything wrong please inform me. thanks Class 1 is the only class that uses the isReset() code so i hope this helps u guys in...

Setting background images in JFrame

Are any methods available to set an image as background in a JFrame? ...

How to transfer objects from Jframe to another Jframe ?

Hi all, I have two JFrames in my application. In the first JFrame there is a JTable. When the user clicks the JTable I want to get the clicked row's object then open the second JFrame and fill its data fields with this object's elements. So how can I transfer objects between JFrames? Can someone give me an example for this? ...

Why does the JFrame in this code react to ActionEvents when only the button object has the .addActionListener?

The button in the code below is to me the only object that should listen for ActionEvents but when I resize the window the circle changes color which should only happen when the button is pressed. Does it in some way use frame.repaint() when resizing the window that generates new values for the drawPanel object or even makes a new draw...

Layering many JPanels and adding them on the fly

Hi all. I'm developing a sim game based on Theme Hospital, which is quite an old game. I've made lots of progress on the underlying workings, however now I am coming to the GUI elements, which I haven't done alot of before. I am still rather new to java. The effect I am trying to create is like shown here... http://www.tubechop.com/watc...

Set size of a Jframe in the Jpanel program?

In the JPanel program, I wrote this: String size = JOptionPane.showInputDialog("What frame length?"); int s = Integer.parseInt(size); and I use the s variable in the body of the code. The problem is, I need to use the variable to also set the size of JFrame, and I don't know how to transfer the variable to that program.. Could I set ...

Making a JPanel manually resizable

I have a JFrame with BorderLayout as the layout manager. In the south border, I have a JPanel, I want this JPanel's size to be adjustable by the user, i.e. the user can click on the edge of the border and drag it up to make it larger. Is there any way you know that I can do this? ...

How do I remove component from JFrame that uses BorderLayout.

The container uses a BorderLayout. I have a JPanel that I added to the CENTER. However the JPanel doesn't have a variable name for it. I could do contents.remove(nameofPanel) But since I added it like this contents.add(new CustomJPanel(), BorderLayout.CENTER); Now I'm trying to remove the current CustomJPanel and add a new one. How d...

How to programmatically close a JFrame

What's the correct way to get a JFrame to close, the same as if the user had hit the [x] button, or pressed Alt+F4 (on windows)? I have my default close operation set the way I want, via setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); and it does exactly what I want, with the aforementioned controls. This question isn't about that. ...