Byte-Welt Forum

Zurück   Byte-Welt Forum > Projekte > DockingFrames

DockingFrames DockingFrames An extension of Swing, used to flexibly arrange windows. - Ist eine Erweiterung von Swing, mit der flexibel Panels angeordnet werden können.

Antwort
 
Themen-Optionen Thema durchsuchen
Alt 10.06.2010, 09:12   #1
grml starter
 
Registriert seit: 07.05.2010
Beiträge: 32
grml befindet sich auf einem aufstrebenden Ast
Standard Problems with grid

Hi!
I am facing problems with the following grid layout:
Java Code:
  1. CGrid grid = new CGrid(control);
  2.         grid.add(0, 0, 1, 1, component1);
  3.         grid.add(0, 1, 1, 1, component2);
  4.         grid.add(0, 2, 1, 1, component3);
  5.         grid.add(1, 0, 1, 1, component4);
  6.         grid.add(2, 0, 1, 1, component5);
  7.         grid.add(2, 1, 1, 1, component6);
This does not show any dockables allthough it shows them visible in the controller.
Something like this works fine:
Java Code:
  1. grid.add(0, 0, 1, 1, component1);
  2.     grid.add(0, 1, 1, 1, component2);
  3.     grid.add(0, 1, 1, 1, component3);
  4.     grid.add(1, 0, 1, 2, component4);
  5.     grid.add(2, 0, 1, 1, component5);
  6.     grid.add(2, 1, 1, 1, component6);
What is the magic behind it? Setting a 3 as width or height generally destroys the layout in a sense that either components are not visible or the whole layout is empty.

I know the first two numbers are the x- and y- coordinates, but how should I use the third and fourth numbers. I used to have them set to 1, 2 or 3, same as the weightx or weighty settings in a GridBagLayout. Is this correct? As they are doubles I would have suspected them to be so, but I entered e.g. 0.3 or 0.7 for two components in a column which destroyed the layout.
Another thing I have not yet understood is how a list of dockables can be assigned to the same location, especially a list of single dockables. I get the sense of multiple dockables as they tab automatically, but singles?
Thanks for your reply and best regards,
grml

Geändert von grml (10.06.2010 um 09:46 Uhr). Grund: additional info
grml ist offline   Mit Zitat antworten
Alt 10.06.2010, 19:22   #2
Beni
Moderator
 
Benutzerbild von Beni
 
Registriert seit: 27.08.2006
Beiträge: 571
Beni befindet sich auf einem aufstrebenden Ast
Beni eine Nachricht über Skype™ schicken
Standard Re: Problems with grid

1. Comparing to a GridBagLayout, the 3. and 4. parameter would be gridwith and gridheight.

Imagine a sheet of paper on which you draw your layout. You draw a set of boxes (box = Dockable) preferrable such that they do not overlap and such that there are no empty spaces between them. Each box has a position and a size. The position is the 1. and 2. parameter ("x" and "y"), the size is the 3. and 4. parameter (hence they are called "width" and "height").
This sheet is the "grid", and magically the sheet is big enough that all your boxes always fit in.

Afterwards someone has a close look to this sheet, finds out how to organize the Dockables, and "deploys" them (the grid has no use afterwards).


2. As for the "list of dockables": first of all, "add" has a vararg-argument. You can just call something like:
Java Code:
  1. grid.add( 1, 2, 3, 4, dockable1, dockable2, dockable3 );
... and second: if two Dockables have the exact some position and size, then they are also put together.


3. The difference between single- and multiple-Dockables is how they are handled when the framework stores the layout (the position, size and relations between all elements).
- Single-Dockable: just its identifier gets stored. The client is responsible for storing its content. Each single-Dockable has a unique identifier set by the client, no two dockables can share the same identifier.
- Multiple-Dockable: the client has to provide a factory which is used to store the content of the Dockable. There can be many dockables for each factory, they are not unique.

Apart from that, single- and multiple-Dockables are handled exactly the same way everywhere (unless the client application treats the differently). It has nothing todo with tabs.



Btw.: if I run your settings the Dockables clearly appear. The framework might not always guess correctly how to fill empty spaces and resolve overlappings, but no component gets hidden or forgotten.
Java Code:
  1. public class Dock10 {
  2.     public static void main( String[] args ){
  3.         JFrame frame = new JFrame( "Demo" );
  4.         CControl control = new CControl( frame );
  5.        
  6.         frame.add( control.getContentArea(), BorderLayout.CENTER );
  7.  
  8.         CGrid grid = new CGrid( control );
  9.         grid.add( 0, 0, 1, 1, createDockable( "Red", Color.RED ) );
  10.         grid.add( 0, 1, 1, 1, createDockable( "Green", Color.GREEN ) );
  11.         grid.add( 0, 2, 1, 1, createDockable( "Blue", Color.BLUE ) );
  12.         grid.add( 1, 0, 1, 1, createDockable( "Cyan", Color.CYAN ) );
  13.         grid.add( 2, 0, 1, 1, createDockable( "Magenta", Color.MAGENTA ) );
  14.         grid.add( 2, 1, 1, 1, createDockable( "Yellow", Color.YELLOW ) );
  15.        
  16.         control.getContentArea().deploy( grid );
  17.  
  18.         frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  19.         frame.setBounds( 20, 20, 400, 400 );
  20.         frame.setVisible( true );
  21.     }
  22.  
  23.     public static SingleCDockable createDockable( String title, Color color ){
  24.         JPanel panel = new JPanel();
  25.         panel.setOpaque( true );
  26.         panel.setBackground( color );
  27.         return new DefaultSingleCDockable( title, title, panel );
  28.     }
  29. }
__________________
Beni ist offline   Mit Zitat antworten
Alt 11.06.2010, 07:57   #3
grml starter
 
Registriert seit: 07.05.2010
Beiträge: 32
grml befindet sich auf einem aufstrebenden Ast
Standard Re: Problems with grid

Thanks Beni!
Do I understand the last two parameters correctly when I say that when e.g. width = 1 and height = 2 that the dockable spans over two rows or does it mean that the dockable is twice as high as wide?
This is important for me as I use the coded layout as default layout which is called by a "restore layout" button. It does then not read from the written data-files but from this layout. Therefore, I would like to be as flexible as possible to "initialize" the layout via code. Or are there easier solutions for that?
Thanks and best regards,
grml
grml ist offline   Mit Zitat antworten
Alt 11.06.2010, 08:14   #4
Beni
Moderator
 
Benutzerbild von Beni
 
Registriert seit: 27.08.2006
Beiträge: 571
Beni befindet sich auf einem aufstrebenden Ast
Beni eine Nachricht über Skype™ schicken
Standard AW: Problems with grid

The rows/column analogy is correct. And something like "width = 1.5" would mean 1 + a half row.

For your button that is certainly a valid solution. (Personally I prefer to store the "default layouts" in a file that never gets overridden, because then I can drag & drop my layout one time and don't have to think about how to build it in code.)
__________________
Beni ist offline   Mit Zitat antworten
Alt 11.06.2010, 10:26   #5
grml starter
 
Registriert seit: 07.05.2010
Beiträge: 32
grml befindet sich auf einem aufstrebenden Ast
Standard Re: Problems with grid

OK. Thank you That would mean anybody would have the possibility to delete the default layout files (when sHe finds them in the directories) which could cause an error when restoring that. I bypass that by trying to model the layout within the code.
Thanks for your input.
BTW: I have never mentioned how great your framework is. Congratulations and thanks for that and your superb support!
grml
grml ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Stichworte
grid width height


Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche

Forumregeln
Es ist Ihnen erlaubt, neue Themen zu verfassen.
Es ist Ihnen erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.


Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Problems when updating title of dockable MMM DockingFrames 5 27.04.2010 09:01
Problems with v1.0.8p3a and v1.0.7 ThomasHilbert DockingFrames 5 17.03.2010 20:16
Link problems on Windows 7 Unregistered JCuda 4 14.03.2010 22:36
Getting grid co-ordinates of a dockable just before it closes parag DockingFrames 1 18.09.2009 07:13
[Erledigt] Grid und BorderLayout kombinieren swerflash Java Standard Edition (J2SE) 7 21.12.2006 16:59


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:09 Uhr.


Powered by vBulletin® Version 3.8.2 (Deutsch)
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.