Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 9:42 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Creating custom widgets
PostPosted: Sun Jun 05, 2011 9:31 pm 
Offline

Joined: Sun Jun 05, 2011 9:15 pm
Posts: 2
I'm working with the twl theme editor and I was trying to look for an example on creating custom widgets and I couldn't find any examples.

What I basically want to do is create an area with multiple buttons that is enclosed within a frame. I guess frame with widgets is close to what I want but I can only work with one button.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2011 11:04 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
The Theme Editor can load custom code.

See "Widgets" -> "User widgets" -> "New classpath".

To use user custom widgets you need to follow a few basic rules:
- must inherit (indirectly) from Widget
- must have a public no-argument constructor (eg default constructor)
- must not call Display.create/destroy etc
- don#t add TWL.jar or LWJGL.jar in the class path

If a class doesn't fit the requirement the tool will show you the reason why it did not load that class.

Once you have loaded your class path the custom widgets are available in a new sub menu under "Widgets".

You can modify most java bean properties of your widget in the bottom right panel of the editor.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2011 9:11 pm 
Offline

Joined: Sun Jun 05, 2011 9:15 pm
Posts: 2
Could you show me a quick code example? I've never done anything like this.

Since you said
Quote:
You can modify most java bean properties of your widget in the bottom right panel of the editor.


Lets say I'm working with more than one button and I want to change the position for both of them. Whenever I go to edit the position of one of the buttons all the other buttons have the same position parameters. So how would I go about changing the position of only one button?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2011 6:09 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Ok, I didn't understand your question. You say you have a hypothetical bug in a hypothetical use case?!?

In the theme editor you have your UI tree on the top right.
The bottom right pane shows the properties of the selected widget (from top right pane).

So you can edit the position and size of every widget separate - BUT the theme editor is not a UI layout editor. It is designed to the edit the theme.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Oct 19, 2012 1:42 pm 
Offline
User avatar

Joined: Thu Jun 14, 2012 12:33 am
Posts: 17
I tried load custom widgets, but I got an exception:

Quote:
Time: 17:37:04
Category: Test widgets
Title: Could not loaded any user widget

Loaded from the following class path:
F:\Develop\Java\ciot\out\production\test\twl\comps

The following class could not be loaded:
test.twl.comps.NiceTree : can't load class: test.twl.comps.NiceTree


The Class:

Code:
package test.twl.comps;

import de.matthiasmann.twl.TreePathDisplay;

public class NiceTree extends TreePathDisplay {

    public NiceTree() {
    }
}


What am I doing wrong?

P.S.
I had NiceTree.class


Top
 Profile  
 
PostPosted: Fri Oct 19, 2012 6:03 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
You specified the wrong class path. As your fully qualified class name is "test.twl.comps.NiceTree" which must be in this file and path:
Code:
<classpath>/test/twl/comps/NiceTree.class
where the element <classpath> is the root of the class path which needs to be specified. These are fundamental Java basics.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Fri Oct 19, 2012 7:11 pm 
Offline
User avatar

Joined: Thu Jun 14, 2012 12:33 am
Posts: 17
MatthiasM wrote:
You specified the wrong class path. As your fully qualified class name is "test.twl.comps.NiceTree" which must be in this file and path:
Code:
<classpath>/test/twl/comps/NiceTree.class
where the element <classpath> is the root of the class path which needs to be specified. These are fundamental Java basics.


I corrected the path, but It's wrong so. But I got successful result, when I used .jar.

Code:
<?xml version="1.0" encoding="UTF8" standalone="yes"?>
<classpath>
    <entriesToScan>
        <entry>file:/F:/Develop/Java/ciot/out/artifacts/twlib_jar/twlib.jar</entry>
    </entriesToScan>
    <entriesDependencies>
    </entriesDependencies>
</classpath>


Top
 Profile  
 
PostPosted: Fri Oct 19, 2012 8:18 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Well - I'm using file based and JAR based all the time so it is working. Which means you somehow did not configure it correctly. In your case the correct path would have been:
Code:
F:\Develop\Java\ciot\out\production\

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group