Y
Y
Yuri_Prime2013-05-01 15:07:34
Java
Yuri_Prime, 2013-05-01 15:07:34

Tables in Java?

The crux of the matter is this. There are a large number of files, certain information is extracted from each (roughly speaking, tags, the String class, plus the file name and path to it). Accordingly, they are different for each file. There is an idea to create a class with fields containing these tags, that is, for each file there will be an instance of this class. A display problem arises: it is most convenient through a table, since for each file the tags can be processed and changed (at the end of the execution, just check if the table parameters have changed and, if so, overwrite the tags in the files). But in the table, if I understood correctly, it turns out that you can’t really cram objects of this class, you can cram only field values. It would be more correct to abandon the table and use something else, working with instances of my class with tag fields, or to abandon the class with tags and just write these same tags directly to the table? Or maybe there is some other option that I do not see, due to little experience?
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri_Prime, 2013-05-01
@Yuri_Prime

Sorry for the somewhat confusing question. The table is an object of the JTable class. We take a bunch of files, extract tags from them, and put the tags into a table, which is a JTable, in order to work with them later. There is also an option to create your own class with fields containing tags and create an instance of the class for each file, and then somehow present the fields of all instances of this class and work with them. So I wander from one option to another.

J
JuniorIL, 2013-05-02
@JuniorIL

Well, the idea is basically correct.
Firstly, I would create some kind of my own entity that would denote such a record. Among the properties, I would indicate File, if necessary, you can physically access it, i.e.

public class SuperDeed {
    private File file;
    private Set<String> tags;
    private String name;
    
    ...(getters, setters, constructor)

}

Now, from file, you can extract the path, file name, etc. I do not advise you to work directly with the IO API in this entity, this is a model and it should not take care of any IOExceptions.
The question is why all this, if 1) you can save to the database and not suffer with files 2) if you already work with files, use something like XStream or Jackson and save as XML / JSON
Tags can be displayed separated by commas, check when saving whether the user has added yet. For all these joys, you will need to play with TableModel, see more details here . You will also need to write a validator for tags, i.e. your own CellRenderer (to allow only commas).
Something like that, the general idea. More precisely, to say it is necessary to remember swing (I have not written on pure swing for three years), but I think the general idea is enough. Next time, try to explain your problem in more detail and use "clarify" rather than "answer" for clarification, and put the right tags (working with swing - swing tag, etc.).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question