java JFrame setSize - java

I am loading a JFrame showing the company logo and credits etc before starting the main application. I am having some problems. Fist of all, the size of my new JFrame can never be set. The JFrame looked fine when I previewed it under netBean but came out smaller every time. I tried to do it with a new constructor and setSize(), but still not working. Second, the JFrame has been loaded very slowly. No images and everything could be loaded and the JFrame stays blank for at least five seconds, really kind of annoying. Do it have anything to do with where I put the image files?
Thanks alot.

I am loading a JFrame showing the company logo and credits etc before starting the main application. I am having some problems. Fist of all, the size of my new JFrame can never be set. The JFrame looked fine when I previewed it under netBean but came out smaller every time. I tried to do it with a new constructor and setSize(), but still not working.
It is very difficult to suss out what is wrong without seeing your code, but having said that, your comment about this being a NetBeans-generated GUI suggests that the code will be very large and hard to read and interpret. It is for this and many other reasons that I am not a fan of using NetBeans to generate GUI's, especially for newbies who are just learning how to use Swing. I suggest that you write out your GUI code by hand with some user-friendly layout managers, nested by nesting JPanels if necessary. If you do it this way, you'll have some greater flexibility and control in the construction of your GUI, and you'll also have readable and debuggable code that you can post here for our assessment and help should it not work out right for you.
Second, the JFrame has been loaded very slowly. No images and everything could be loaded and the JFrame stays blank for at least five seconds, really kind of annoying. Do it have anything to do with where I put the image files? Thanks alot.
This sounds like a threading issue. I'd just load the images for the intro GUI first, then show the intro window, and then in a background thread, load any other resources that the program needs.
Having said all this, you probably want to look into using Java's own splash screen as this may do all that you're trying to cobble together on your own. The tutorials can help you with this (please click on link above or here).

Much unclear question description though I want to point some tips...
Do it have anything to do with where I put the image files?
If you mean your JFrame title image so you can use its setIconImage() method
Fist of all, the size of my new JFrame can never be set.
It is quite strange :( because you can always write code like a
JFrame aFrame=new JFrame();
aFrame.setSize(x,y);
... to control your frame scale
Second, the JFrame has been loaded very slowly. No images and
everything could be loaded and the JFrame stays blank for at least
five seconds
It may be caused by single thread overloaded but still to analyze the problem show the main class code or its exceptions stack trace
previewed it under netBean but came out smaller every time
what component do you use to paint your logo? And how do you paint it? Show the snippet

You can set the size by right click on the jFrame and
Set Default size
(netbeans design view)
I hope this is what you want

this may be useful for you?
JPanel aa = new JPanel(new GridBagLayout());
aa.setMaximumSize(new Dimension(500,500));
aa.setMinimumSize(new Dimension(490,490));
aa.setBorder(BorderFactory.createLineBorder(Color.black));

I opened the properties dialog for my JFrame and set "minimum size" field to [500,500] but that did not work.
What did work for me was selecting the "..." button at the right of the "minimum size" property. In the "JFrame Mininumsize" dialog as follows:
set dropdown (Set forms minimum size property using: ) = "Custom Code"
set code in (Form.setMinimumSize( ) ) = "new Dimensiom(500,500)"

Related

Using setContentPane() method correctly

I have created a java program in which i have used the setContentPane() method on a JFrame. My problem is that the frame does not get updated by the new panel immediately but gets updated upon resizing the frame.
In my program the size of the JFrame is 600,600.
To temporarily avoid this problem, after the setContentPane() method , I have applied a set of 2 statements:-
Frame.setSize(601,601);
Frame.setSize(600,600);
This resizes the frame and brings it back to its original size without showing much change to the user. This is working good and the panel is getting updated.
My question is, am I making any mistake and there is some other way to do it? Or I can continue using this trick? Please answer if there is any other(right) way to do it.

Java Swing: JPanel only adds components when JFrame window is maximized or it's size changed

I have a Java program that creates a JFrame, a JPanel, and several JTextAreas. I set the text of the JTextAreas and then add them to the JPanel. When the program loads, I only see the empty JFrame.
However, if I maximize, or change the size of the program window, the JTextAreas, and their respective texts appear on the screen.
How can I correct this so that the program loads, with the text areas populated, without the need to mess with the window? My apologies in advance for being a Swing noob.
My guess: You need to call setVisible(true) on the JFrame after adding all components to it.
Next time, or this time if this doesn't answer your question, please post pertinent code. We're terrible at reading minds or guessing at code not shown. Please check out the Jon Skeet blog: Asking the Perfect Question. It will give you great suggestions on how to create better more complete questions and thus get better answers.

Images in Swing GUI-NetBeans

I already designed many JPanel's for my application in Netbeans now i want to ..
Add background images to all jpanel's in which i had some jcomponents already.
And i want it to do it for jdialog too.
I need to design a JMenu with images and menu name.
But already i saw many examples for background images in that they are adding there components through coding im doing it in Netbeans.Is it possible to set it for the main JFrame then i can leave the jpanel's.
If you use netbeans background image can be added using a simple method. I don't know whether it is a good practice, but it is really easy. See this video.

Link between two JFrames

Link between two JFrame using JMenu
I have an application where I have to move to another frame by clicking a menu. for example, on a file menu, I click on add which will bring out a new frame where operations can be carried out. what code(s) can i use in Netbeans?
I used it to open another JFrame but when I exit the new JFrame both frames are closed ....
there is something wrong in ma code plz help me in that prob....
You have to set the defaultCloseOperation to something else then EXIT_ON_CLOSE. Please refer to the documentation for JFrame for more information. I suspect that the second JFrame should only have HIDE_ON_CLOSE though.
do you need to use jframes? why not jdialogs? (the dialog window (which can pop up) does not have to be modal.
if you have two different frames, that can make parentage (which window belongs to which frame) something you need to keep track of more assiduously.
please tell us in more detail what you are trying to accomplish; that will help in picking the correct widgets to be used. if things are hard to do/code in swing, then there's probably an easier way with other widgets/components, imho.
good luck!

Java JPanel redraw issues

I have a Java swing application with a panel that contains three JComboBoxes that do not draw properly.
The combox boxes just show up as the down arrow on the right side, but without the label of the currently selected value.
The boxes will redraw correctly if the window is resized either bigger or smaller by even one pixel.
All of my googling has pointed to calling revalidate() on the JPanel to fix this, but that hasn't worked for me.
Calling updateUI() on the JPanel has changed it from always displaying incorrectly to displaying incorrectly half of the time.
Has anyone else seen this and found a different way to force a redraw of the combo boxes?
Can you give us some more information on how you add the combo boxes to the JPanel? This is a pretty common thing to do in Swing so I doubt that it's a JVM issue but I guess anything is possible.
Specifically, I would double check to make sure you're not accessing the GUI from any background threads. In this case, maybe you're reading the choices from a DB or something and updating the JComboBox from a background thread, which is a big no-no in Swing. See SwingUtils.invokeLater().

Categories