Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

Java Swing Printing--Jlabels With Missing Characters
Started by gregwarner, Apr 18 2012 01:26 PM
setpreferredsize printing
30 replies to this topic
#25
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.
If you plan to call validate again on the same container, you may want to prefer revaldiate() though.
#27
Posted 20 April 2012 - 05:51 AM
Did you do setInsets?
Otherwise try setSize, minimumsize, preferred size, bounds.. lol
Otherwise try setSize, minimumsize, preferred size, bounds.. lol

#28
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.
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
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...
#30
Posted 20 April 2012 - 06:10 AM
From the JComponent.getInsets() Javadoc:
So I set a blank border for my insets.If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.
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
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.
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.

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
![]() Printing a string after If statementStarted by Bitlynk, 15 Apr 2013 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Keeping content together when printingStarted by hinkeltje, 21 Feb 2013 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Force printing on A4 landscape formatStarted by hinkeltje, 21 Feb 2013 ![]() |
|
![]() |
||
Language Forums →
PHP →
how to shuffle contents fetched from database before printingStarted by alamin, 13 Feb 2013 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
[C++] Printing a whole text file in separate linesStarted by qyler, 01 Feb 2013 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download