Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Java Swing Printing--Jlabels With Missing Characters

setpreferredsize printing

  • Please log in to reply
30 replies to this topic

#25 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 20 April 2012 - 05:45 AM

Judging by the javadoc that goes with validate it seems to do the thing.

If you plan to call validate again on the same container, you may want to prefer revaldiate() though.
  • 0

#26 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 20 April 2012 - 05:49 AM

None of those options seemed to do anything. I'm still getting a blank page when I print.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#27 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 20 April 2012 - 05:51 AM

Did you do setInsets?
Otherwise try setSize, minimumsize, preferred size, bounds.. lol :P
  • 0

#28 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 20 April 2012 - 05:58 AM

I didn't see a setInsets() method. I checked the javadoc on getInsets(), and it says that if a border has been set, it'll get the insets from that, so that's what I did.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#29 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 20 April 2012 - 06:04 AM

Source of the layoutcontainer starts with:
public void layoutContainer(Container target) {
synchronized (target.getTreeLock()) {
  Insets insets = target.getInsets();
  int top = insets.top;
  int bottom = target.height - insets.bottom;
  int left = insets.left;
  int right = target.width - insets.right;
So it has to be set somehow...
  • 0

#30 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 20 April 2012 - 06:10 AM

From the JComponent.getInsets() Javadoc:

If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.

So I set a blank border for my insets.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#31 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 20 April 2012 - 01:10 PM

I fixed my issue with it printing completely blank. Since I wasn't displaying my JPanel on the screen first, the outer JPanel itself that I was trying to print didn't have a preferred size set. I used its own setBounds() method to give it a size, and lo and behold, it printed. (I also had to explicitly call layoutContainer() on its layout manager to force it to give bounds to all its children.)

Now all I have to do is fix this issue with the font metrics giving different string lengths for the screen and the printer at font size 8 pts. :glare:
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid






Also tagged with one or more of these keywords: setpreferredsize, printing

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download