Win a copy of Terraform in Action this week in the Cloud forum!

D R Wilkinson

Ranch Hand
+ Follow
since Oct 29, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by D R Wilkinson

I have an application with a JMenu - a 'File' menu. Amongst other items, this menu has a JMenuItem that triggers saving files when clicked. This JMenuItem starts life in a disabled state (so the user cannot save anything) until something in the project is added, deleted or modified, at which point this 'Save' JMenuItem's state changes to enabled - allowing the user to save the altered project. Once this saving is completed, the 'Save' JMenuItem's state returns to disabled and so on.

The reason for this is that it simplifies the logic behind saving files that have not been altered, closing an altered file needing to trigger a check to see if the project data has altered since... blah, blah, blah. It seems simpler to me to just toggle the state of the 'Save', 'Save as', 'Close', 'Exit', etc JMenuItems appropriately when the user alters some data in a project.

All of this works perfectly when the components that the user is using to alter the data are contained within the same JFrame as the 'File' JMenuItems as the appropriate JMenuItems can be referenced directly as everything is all in the same big application gui class.

It falls down for me when I try to apply the same thing to JPopupMenu's...

Elsewhere in the program I have a JTree that has a customised JPopupMenu that extends JPopupMenu. Amongst other items, this PopupMenu has a JMenuItem that triggers adding a chapter when clicked.

All the above works fine using ActionListeners and actionPerformed method calls.

This is what I want to add but I am very confused as to how to do it.

When the user clicks on the 'Add Chapter' JMenuItem in the customised JPopupMenu, aside from adding the chapter, I want it to send a message to the 'Save' JMenuItem in the 'File' JMenu, telling the 'Save' JMenuItem to change its state to enabled.

As the 'Save' JMenuItem is not a field within the custom JPopupMenu class, I can't reference it directly. I could pass the 'Save' JMenuItem into the JPopupMenu and reference it that way but that seems to tie the two objects very tightly together. I could customise the 'Save' JMenuItem and have it implement the ActionListener interface and so on but as my overall understanding of Java's inbuilt messaging system isn't perfect I started to suspect I may be trying to re-invent Java's messaging system poorly.

I am also using Netbeans which is a very useful tool but is also still a little confusing sometimes.

How do I use Java's messaging system to make the 'Save' JMenuItem listen for and react to, a click on the 'Add Chapter' JMenuItem that is on the customised JPopupMenu?

Thank you for your time.

Darren
15 years ago
Thank you,

The problem lay with the char literal '\' not being added correctly.

Solved it by using "\\"

Not sure if this causes a cross platform problem?

Darren
15 years ago
I am trying to let the user select the directory they want to save a plain text file in and have the program determine the name of the file. The attempt I have made isn't working and the more I read the API, the more confused I am getting... can anyone help me?



Thank you
[ May 06, 2006: Message edited by: D R Wilkinson ]
15 years ago
Hello,

I keep getting the following warning on compilation;

Note: C:\Documents and Settings\Darren\Desktop\Oak\Oak\src\models\BookTreeModel.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

How do I do this using Netbeans 5?

Thank you
The solution was to simply call validate() on the parent component that displays the card layout managed sub-components.

Note To Self : Read the API a little bit more carefully.
I think I may have solved this on my own.

I will post the solution here ( once I am sure ) so it may be of use for anyone else with a similar question.
Hello :-)

I am trying to add three JTabbedPane's ( each with sub-components ) to a JPanel. The JPanel uses a CardLayout and as I need to change the specific JTabbedPane dynamically at runtime, I need to use addLayoutComponent( Container container, Object name ) so that I can change the displayed component by calling show( Container parent, Object name ).

When I add the JTabbedPane's using the GUI editor, the calls to show(...) do nothing - I am guessing that this is because the GUI editor does not automatically detect that components added to a cardLayout managed JPanel usually require dynamic display. Instead, the GUI editor uses a straight forward add(...) method.

I am new to Netbeans. How do I add the JTabbedPane's to a CardLayout managed JPanel so that I can dynamically display specific JTabbedPane's at runtime using show(...)

Thanks.

Darren
Okay...

My renderer is made up of a JPanel with a JCheckBox (west) and a JLabel (center). My editor is the same.

Each tree node ( renderer or editor ) represents one of three 'components' of a book - The book itself containing, chapters, which in turn contain, scenes.

I have an abstract BookComponent class which implements getters and setters for two private fields 'isSelected' and 'componentTitle'. The 'isSelected' field has nothing to do with the selected state of any tree node. It indicates whether the user has selected the book, chapter or scene for exporting, printing, etc.

The three specialised subclasses: Book, Chapter and Scene all extend BookComponent and provide specialised fields and methods.

My renderer needs to display the 'isSelected' state ( using the JCheckBox ) and the 'componentTitle' using the JLabel.

My editor needs to allow the user to edit the 'isSelected' state ( using the JCheckBox ) and the 'componentTitle' using the JLabel of the BookComponent subclass object the tree node represents.

I thought that a tree node renderer queries the user object of the tree node that is currently being rendered, for the values it needs to display and renders them in place.

When a tree node is edited, its display is taken over by a tree node editor.

This editor queries the user object of the tree node that is currently being edited, for the values it needs to display - ie the user objects current state before any editing takes place.

Then it needs to accept any user changes ( checking or unchecking the checkbox, entering text in the label ) and pass these changes on to the user object the tree node is representing.

When a different tree node is clicked on, the tree node that was previously being displayed by an editor is now being displayed by a renderer. As the renderer gets the values to display from the tree nodes user object, the tree nodes should display their new state.

Mine doesn't - when I check a book components tree node check box ( when in editor mode ) this nodes JCheckBox fails to retain its checked state ( when in render mode ). I haven't tackled the JLabel yet.

If I have understood your example properly, the tree node is representing a Color object. When the user changes the colour using an editor, this editor returns a new Color object that represents the new colour.

Mine represents two properties of a specific BookComponent subclass - I cannot have the edited tree node renderer display a new BookComponent subclass object - it needs to display the values of the BookComponent subclass it represents... not a new one.

I am trying to get there but at the moment, in my usage, I am still unclear what this method is supposed to return?
[ March 03, 2006: Message edited by: D R Wilkinson ]
15 years ago
I have read the javadoc on this method but it is a little vague.

Can anyone explain its function in a more definite way.

I am currently adapting the code example at http://www.java2s.com/ExampleCode/Swing-JFC/CheckBoxNodeTreeSample.htmand it is used to return a new CheckBoxNode but I don't understand why or what is calling it?

Thank you.
15 years ago
Thank you for your reply Rajagopal,

The proceedure you describe is what I did first but it didn't work.

If you were to download the HTTPClient zip file, you may be able to see where I am going wrong.

After extracting all the files within it, you will see that the zip file doesn't contain any jar files. The directory structure is...

HTTPClient
|________ ( Files ) Lots of java/class files ( the main ones I need )
|________ ...
|________ ( Folder ) alt
|________ ( Folder ) doc
|________ ( Folder ) http
|________ ( Folder ) https
|________ ( Folder ) shttp

In BlueJ, referencing the root HTTPClient folder is enough for BlueJ to recognize the files within the root folder HTTPClient as being 'importable'.

Netbeans is different though.

As you suggest, I create a new library called HTTPClient then..,

I reference folder HTTPClient for the classpath.
I reference folder HTTPClient for the source.
I reference folder HTTPClient.doc for the javadoc.

In the projects window, I add the new HTTPClient library to the libraries folder.
It creates the following file system..,


HTTPClient
|________ ( Folder ) default folder ( this contains the needed files )
|________ ( Folder ) alt
|________ ( Folder ) doc
|________ ( Folder ) http
|________ ( Folder ) https
|________ ( Folder ) shttp

When I use a class such as HTTPConnection which is at HTTPClient.HTTPConnection according to the javadoc, Netbeans says "package HTTPClient cannot be found". When I run fix imports, netbeans adds import statements such as import HTTPClient.HTTPConnection, then flags them as errors, saying "package HTTPClient cannot be found".

BlueJ just imports HTTPConnection from the root HTTPClient folder.

If you have the time, could you download HTTPClient and see if you can get it to work within netbeans as a library. The download is tiny and includes some small example source code files.

Thank you for your help so far.

Darren
[ January 31, 2006: Message edited by: D R Wilkinson ]
Hello,

I am using Netbeans 5 ( release candidate 2 ) and I am trying to add the HTTPClient library found at HTTPClient.

I have a JDialog which uses this library but all references to HTTPClient objects are not working. NB highlights them saying "Package HTTPClient does not exist". This is after I have run "Fix Imports" and after adding HTTPClient as a library object to NB's Libraries folder in the Project view.

I made the library object by downloading the HTTPClient zip, unzipping it into a folder called 'HTTPClient', then making a new library called 'HTTPClient' in NB, then pointing the;

classpath to C:\Documents and Settings\Darren\My Documents\3rd Party Java Libraries\HTTPClient
source to C:\Documents and Settings\Darren\My Documents\3rd Party Java Libraries\HTTPClient
javadoc to C:\Documents and Settings\Darren\My Documents\3rd Party Java Libraries\HTTPClient\doc

Can anyone who uses Netbeans please help me get this library to work as I am clearly doing something wrong.

I have got HTTPClient to work within BlueJ by simply pointing it at C:\Documents and Settings\Darren\My Documents\3rd Party Java Libraries\HTTPClient and using import HTTPClient.*;

Thank you.

Darren
Hello,

I want to distribute my application from a website via JNLP/WebStart.

Can anyone explain what I need to do in order to achieve this and also, can anyone recommend any web hosts that support JNLP.

Thank you.
15 years ago