aml lopez

Greenhorn
+ Follow
since Jan 13, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by aml lopez

Hello everyone,

I have a problem with printing in Java. I must be missing something but I have found the Java documentation on printing to be scarce and difficult to understand, so I haven't been able to find any solution by myself.

Maybe somebody can give me a hand?

I get this wrong layout: (please see attached screenshot.png)

I am trying to print to a MEDIA SIZE A7. As you can see the layout is wrong. Maybe it's to do with the margins, but how to set them?

Here is my code:





Thank you very much in advance.
14 years ago

pete stein wrote:

aml lopez wrote:Example:

VisiblePanel.add(new Jbutton("test"));

This works for me in Netbeans if VisiblePanel has a layout manager set. Otherwise it doesn't. And as I said there is no need to call revalidate or repaint.


I think that your solution has little to do with adding things at runtime as was specified in the original post. My guess (and guess is all I can do since you didn't post a program but rather a snippet) is that your button was added before the GUI was packed and displayed which is quite a different issue.

On a side note, I highly recommend that you not use NetBeans to generate your Swing code until you've learned how to do it by hand. Going through the Sun Swing tutorials and learning to code Swing will save you worlds of trouble later when you want to tweak your GUI into doing things that it didn't do before. I think that NetBeans code-generation is fine for quick and dirty apps, but using it too much actually stunts your Swing education.



I am sorry but you are right. After checking my code (the one I posted) I think that actually the button is added before the panel is packed.

Therefore, I apologise.

One thing is true if you don't set the layout manager in netbeans, revalidate doesn't work and the new button won't show. So what the asker should do is set the layout manager to flow or whatever he needs and then call revalidate.
15 years ago
Here you have your code. The asker was asking about NetBeans and why it doesn't work in NetBeans. The reason is he hadn't set up a layout manager for the panel. In netbeans the default layout manager is free and not flow. If you set the layout to flow the dynamic components will add perfectly without any need to call revalidate or repaint. However, if you don't set the layout manager in NetBeans the dynamic components won't show even if you call repaint or revalidate.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, but you might as well try running this example in NetBeans (if you even know how to use it) and you'll see that it works perfectly without calling revalidate or repaint.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx , so please do run this code, and save us all some time.



15 years ago
Example:

VisiblePanel.add(new Jbutton("test"));

This works for me in Netbeans if VisiblePanel has a layout manager set. Otherwise it doesn't. And as I said there is no need to call revalidate or repaint.

As for why I answer to a question which is one year old. I stumbled across this post through Google, when I was looking for a solution to the same problem that the asker was having. When I found the solution by myself I thought somebody may benefit it from it in the future, if they are searching through google for a similar problem. I actually just registered on this site to be able to post the solution in case someone may need it in the future.

Got it?

Regards.
15 years ago
There is no need whatsoever to call revalidate or repaint. As long as you have defined a suitable layout for your panel, a simple call to add will do the job.

Regards.
15 years ago
You must set the layout for the panel in netbeans. For example, gridlayout or something.

Good luck
15 years ago