Tool/ API to position a given amount of Swing-objects on a page?!
Hello,
the problem I have to solve is, that I need to position a given amount of Swing-Objects. The objects are JTextfield's, JLabel's, JCheckBox's and JComboBox's.
Text and content are defined for all this objects.
I need a tool or API where I can do a free positioning of this objects on one page. The size of the page have to be variable in both directions.
After the positioning of the objects I want to receive a file with a the positions of each object.
Please help,
thanks
# 1
Hi,
I've created a customizer framework for such tasks: Move and resize components with the mouse and allow further customizations. "Snap-to-grid"-feature included! Maybe you find it useful as a base. (It's open source!)
I started to write a tutorial (still under construction!):
http://softsmithy.sourceforge.net/lib/docs/tutorial/swing/customizer/index.html
For adding components see:
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/CustomizerBar.html
To customize properties use:
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JCustomizerPropertyTable.html
Register it to the SelectionManager of the JCustomizerPane and set the CustomizableProperties-property of the JCustomizer objects.
Also have a look at the subclasses of JCustomizer.
E.g. there are
customizers for images & shapes:
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JXIconCustomizer.html
a label customizer with inline editing:
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLabelCustomizer.html
a line customizer:
http://softsmithy.sourceforge.net/lib/docs/api/org/softsmithy/lib/swing/JLine2DCustomizer.html
And there are many classes providing support for menu- and toolbar-actions. (Incuding support for some of the "Java Look and Feel Graphics Repository" actions.)
Look at the *.swing and the *.swing.action packages.
Just ask me if you don't find them.
Homepage:
http://www.softsmithy.org
Download:
http://sourceforge.net/project/showfiles.php?group_id=64833
Source:
http://sourceforge.net/svn/?group_id=64833
http://softsmithy.svn.sourceforge.net/viewvc/softsmithy/trunk/lib/src/org/softsmithy/lib/
API:
http://softsmithy.sourceforge.net/lib/docs/api/index.html
If you have questions just ask me!
-Puce
Pucea at 2007-7-12 23:11:03 >

# 2
Hi again,
looks very well. I tried the the changing of the positions and I think that it can be useful.
I want to use it in a way like that:
0. I define the components in my applikation.
1. The appl. opens a dynamic [CustomizerFrame] with all my defined components, it doesn't makes no point how much components.
2. The user positions the components on the [CustomizerFrame] where he want to have them.
3. He have to save the positions (How I don't know) and he will be back in my appl.
4. Later on the positions will be needed by an other part of the appl. (I save them in a DB).
5. The user can change the positions in my appl. again and again in that way.
My problem is:
How can I save the positions after the user finished positioning of the components? In a file? Maybe in an objectarray, as a return value, which I have to parse?
Thanks for your reply
# 3
> My problem is:
>
> How can I save the positions after the user finished
> positioning of the components? In a file? Maybe in an
> objectarray, as a return value, which I have to
> parse?
>
It depends how this part is linked to the rest of your program and what informtion you exactly need and what you want to do with it.
The JCustomizerPane is a subclass of Container, so you can get all components either from the JCustomizerPane or from its LayoutManager.
But I think a better way is to "remember" what customizers you added at creation time and link them with your business objects. After the user has finished the customization task, iterate through your business objects and get the information (x,y,width, height,...) from the associated customizer.
-Puce
Pucea at 2007-7-12 23:11:03 >

# 4
I used your exampleClass and tried it to get the positions and it works. I have only used one Component, but more aren't more difficult.
Here are the changes, italically emphasized:
.
.
.
public class TextCustomizersSample extends javax.swing.JFrame {
JButtonCustomizer checkBoxCustomizer = new JButtonCustomizer(new JCheckBox("Double click to edit this check box!", true));
/** Creates new form TextCustomizersSample */
public TextCustomizersSample() {
final TextCustomizersSample thisFrame = this;
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
thisFrame.setVisible(false);
}
});
.
.
.
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) throws Exception {
final TextCustomizersSample sample = new TextCustomizersSample();
Thread test = new Thread(new Runnable() {
public void run() {
example.setVisible(true);
}
});
System.out.println("Started");
System.out.println(" X Pos: "+example.checkBoxCustomizer.getLocation().x);
System.out.println(" Y Pos: "+example.checkBoxCustomizer.getLocation().y);
test.start();
Thread.sleep(500);
while(example.isVisible()){
Thread.sleep(500);
}
System.out.println("Closed");
System.out.println(" X Pos: "+sample.checkBoxCustomizer.getLocation().x);
System.out.println(" Y Pos: "+sample.checkBoxCustomizer.getLocation().y);
example.dispose();
}
.
.
.
}//end
Do you know how to show the text of an checkbox before the box and not after? Is it possible? Maybe to show only one Object, but use two in the background (Label and checkbox as one CustomizerCheckBox)?
thanks so far
Message was edited by:
Martin_1986
# 5
>final TextCustomizersSample thisFrame = this;
>
You don't have to do this. 'This' should be accessible from anonymous classes.
> Do you know how to show the text of an checkbox
> before the box and not after? Is it possible? Maybe
> to show only one Object, but use two in the
> background (Label and checkbox as one
> CustomizerCheckBox)?
>
This should be a property of JCheckBox. Maybe it's setHorizontalTextPosition. Else check the API!
-Puce
Pucea at 2007-7-12 23:11:03 >

# 6
Yeah, you are right:
jCheckBox.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
Ok, unfortunately the components in the object are on the right border. And this doen't help:
jCheckBox.setAlignmentX(JCheckBox.LEFT_ALIGNMENT);
also the setArligmentX doen't work on the Customizer object:
jCheckBoxCustomizer.setAlignmentX(JCheckBox.LEFT_ALIGNMENT);
Any idea?
Thanks
# 7
Did you try setHorizontalTextPosition? setComponentOrientation is more for languages, which write from right to left, I think.-Puce
Pucea at 2007-7-12 23:11:03 >

# 8
You are right:
jCheckBox.setHorizontalTextPosition(JCheckBox.LEFT);
puts the Text to the left site of the box!
1. I have my owne Buttons with functions.
2. The CutomizerPane is in the middle, in a scrollpane.
3. Now I can create a page with my components.
4. Position all object like I want to do it.
5. Measure all positions and siezes one Buttonaction.
So far so good, realy thank you.
But some difficults left.
- How can I display a Textfield together with a description like the description of a checkbox?
Message was edited by:
Martin_1986
# 9
There are several ways, depending what you want:
a) if you want to place them individually, add the JTextField and the JLabel to a JCustomizer of its own.
b) if the user should be able to edit the description, use a JLabelCustomizer
c) if you don't want to allow to place them individually, add them to a JPanel, then add this JPanel to a JCustomizer.
d) if you don't want to allow to place them individually, but want to allow editing of the description, extend the AbstractTextCustomizer (see Tutorial).
-Puce
Pucea at 2007-7-12 23:11:03 >

# 10
Very well, that was what I looking for.Thanks again.See you