I writing a java program that will read the content of JFrame and based on the value of that an xml file will be created which will contain the attributes and its corresponding value.
I have two classes one having java swing and another creating an xml file.
On my frame i have few check boxes and few combo boxes and I want to create the xml containing attribute and value of these.
I am not able to set the value of these attributes at all in my CreateXML.java file.
If anybody has some solution please help me out.
Regards,
SHK
AlexR is basically right.
However, a far simpler solution to the larger problem is to look into the usage of XMLEncoder, which should handle all of this for you.
JFrame is an indirect subclass of Container that implements method public Component[] getComponents(). Once you have reference to you JFrame you can iterate over its components and create XML if you need. Pay attention that if one of the components is instance of Container you should go inside recursively.
I believe that this is what you should implement into your CreateXML class.
Related
I'm working on creating a basic user interface and I wanted to try and create a portion that is in a scrollTaskPane and is capable of holding multiple entries. As I'm going about creating it I can obviously test it with a simple amount of entries but I'm confused how I can go about later allowing for it to take input to create entries in the scrollTaskPane of maybe 1 entry one time, and then later needing to allow for input of 20 entries. I only know how to use absolute positioning and am trying to figure out the best way to go about it. I also need to later be able to select each entry.
For the entries that will eventually be called and displayed in my interface, I'm planning to store them in a simple text file and use a semicolon as a delimiter between the task "Type" "Name" "Description"(which will be accessible through a button) and "Due Date". Or I may try to learn to use a database for the information. But I haven't decided yet and don't know anything about connecting a database with a java program.
This is the current look (the scrollTaskPane in the middle). And my goal is to put in entries that are each rectangle boxes going across the scrollTaskPane with a checkbox on the end of them. Should I use some sort of grid layout? Or something else? I'm a beginner at user interfaces, so any help is appreciated!
You can make a custom layout, and then keep adding those layout. So extend a layout class, add TextField and a check box in the layout. Initialize the layout with your values, add then add to the ScrollTaskPane.
I have a JList inside a JDialog that contains names, by double-clicking a name it should get the name somehow and insert it to a String inside another form, basically I know how to do it with when only one form is using this JDialog (Main.setSelectedName(...)), but I'm having a hard time implementing it the usage of two or more forms.
Any suggestions?
create some "holder" object and use it as "clipboard" in another forms
I am reading in information from an xml file where i have no idea how much information is there until i read it in. I dynamically create Jtextfields and can get the information to appear on them. I am trying to add a documentlistener to those text fields so that a user can change the data and it will automatically update the xml file every time a number is changed. The problem is that there is no reference to the JTextField to get the text from and it is causing a compiler error. Is there a way to do this?
Use a factory style setup.
Basically, create a method or class that will create a JTextField. Pass it the reference to the node that it will be responsible for.
Create the text field and register the DocumentListener to it...although, I'd be wary about using a DocumentListener personally, maybe a ActionListener and/or FocusListener might be more suitable, but hay.
I've been trying to freshen up on my Java knowledge and I've been building a small GUI program and I've been running into a bit of a problem.
Basically, I have a JList which I'm currently populating with strings from an object from one of my classes which implement AbstractListModel which we can call my ItemList class. It contains an ArrayList of objects of the type Item which implements Serializable.
But, what I'd like to do is rather than populate my JList with a bunch of strings I'd like to populate it with some kind of string + JTextField combination so I can see one property of each Item object while also being able to update another property by changing the JTextField.
Now, what I'm looking for is the simplest possible way of doing this, and I am assuming there is a (relatively) simple way to do this since it's such a common thing to want to do in a GUI application (although I wouldn't put it past Java and Swing to make it convoluted and complicated).
So, what is the correct way of doing this?
No need to ever use String objects. Instead:
Put Item objects in the JList.
Add a ListCellRenderer to the list, to show the Item object the most user friendly way.
When the user selects an item, show the details in a different place (I'm thinking a panel with 2 columns of labels and text fields, and two rows - one for each attribute, and perhaps a button to Save)
The edit controls would best be encapsulated in a panel that can then hidden when not required, & put in a variety of places, e.g.
Below the list
In the main part of the GUI
displayed in a JOptionPane or a (modal or not) JDialog
Here is an example of placing the 'view/edit panel' (the file details) below the selection component (the table).
I am trying to make a properties frame just like the one in netBeans (or Visual Studio). My problem is that I don't know exactly how to design it. First I thought I'll make it with JTable (2 columns, multiple rows) but then I realised that on the second column I will have different types of values (booleans, String, color choosers, etc.), but I think that JTable allows only 1 type of data to be placed in a column.
I would like someone to tell me "JTable allows multiple data types on the same column" and show me how to do it, or tell me a different approach to the problem.
You can perfectly tell a JTable to have a column that contains Object, this way you will be able to put whatever ou want in.
BUT.
You'll then have to implement a very good TableCellRenderer/TableCellEditor pair in order to display whatever the cell contains.
Another option would be to use a Grid or GridBag layout inside of a JScrollPane, then dynamically populate the cells of the grid with different editors depending on the data type of the property.
If you can use external libraries, the JGoodies FormLayout is really suited to create such dialogs. Just take a look at the screenshots in their demo.
There is also a rather good PDF available containing with some examples and explanations.