aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Why do the sizes of my components change when I specify a look-and-feel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why do the sizes of my components change when I specify a look-and-feel?" Watch "Why do the sizes of my components change when I specify a look-and-feel?" New topic
Author

Why do the sizes of my components change when I specify a look-and-feel?

Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 485
Why do the sizes of my components/containers change when I specify a look-and-feel or change look-and-feel repeatedly,with different layouts or without layout?


Millions saw the apple fall, but Newton asked why.
If you understand, say "understand". If you don't understand, say "don't understand". But if you understand and say "don't understand". How do I understand that you understand? Understand!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Why does that surprise you?


luck, db
There are no new questions, but there may be new answers.
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 485
Why does that surprise you?

Because i can not find proper answer/article/post etc about it.
I write following code:-

Got answer :-

When i search in google, about javax.swing.plaf.metal.MetalTabbedPaneUI$TabbedPaneLayout
i got Class MetalTabbedPaneUI.TabbedPaneLayout.
By reading this i got Class MetalTabbedPaneUI.
& by reading it, i got Class ComponentUI.
In this 2 lines written

The base class for all UI delegate objects in the Swing pluggable look and feel architecture. The UI delegate object for a Swing component is responsible for implementing the aspects of the component that depend on the look and feel. The JComponent class invokes methods from this class in order to delegate operations (painting, layout calculations, etc.) that may vary depending on the look and feel installed.


When i run program with tabbedPane.setLayout(new BorderLayout(0, 0)); not commented.
Then i got result:-

But same with code & import & declaration for panel not commented,( but all for panel_1 is commented) & run program, i got result same as above
But when both panels (panel & panel_1) are not commented any more then i got result:-

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at javax.swing.plaf.basic.BasicTabbedPaneUI.paintTabArea(Unknown Source)
at javax.swing.plaf.basic.BasicTabbedPaneUI.paint(Unknown Source)
at javax.swing.plaf.metal.MetalTabbedPaneUI.paint(Unknown Source)
at javax.swing.plaf.metal.MetalTabbedPaneUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at java.awt.Window.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

tabbedPane.getLayout() =java.awt.BorderLayout[hgap=0,vgap=0]


Same there are 2 more commented lines at different locations regarding frame visibility, when try to different cases i got different answers.
But look & feel do some calculation to set x,y & width & height of containers/components in swing program.
Is there necessary to set size, set preferred size, set minimum size, set maximum size, x,y ,bounds, location etc all for get fix values when we try to see in print statement?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Mandar Khire wrote:Is there necessary to set size, set preferred size, set minimum size, set maximum size, x,y ,bounds, location etc

What do you find when you go through the examples in the layout tutorial?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18150
    
    8

Why would anybody write a post about that? The whole point of layouts and look-and-feels is that they will display the same data in different ways. So the answer to the question "Why do they display the same data in different ways?" is profoundly uninteresting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why do the sizes of my components change when I specify a look-and-feel?
 
Similar Threads
Different Swing Components on Windows and Solaris
Resizing grids in GridLayout
help needed for swing questions.
JOptionPane.showConfirmDialog question
Frame and JFrame