Could somebody give me a suggestion on how to simply and effectively make GUI representation of directories which are contained inside the database. Now, getting information using SQL queries is one thing. I can do that.
In fact using separate small examples I can put a file inside the database along with his information and I can get the file out of the database. The thing is I was just doing this without GUI, just to test does it work.
Now I need a GUI of this and I really don't know where to start. DO I use JTable, JList or something third? Also, I think I need an multidimensional array because I have, for example, id of a file, name_of_file and size.
So I need different types to put them in: int, String and int.
Also, I need to obviously hide the id of a file from the user yet keep it at the same time in order to be able to reference it.
How do I hide it in a GUI component?
So, let's say that I have a database table for files with these columns:
id, name, size, binary_of_file.
My real table has a bit more of columns like, id of a parent directory, id of a owner, etc. but for now this is not important.
So, I tell database to give me all info about the file (except it's binary because I just want to list the files):
...
ResultSet rs = statementObject.executeQuery("SELECT id, name, size FROM Files;");
while(rs.next()){
//Where do I store the values in? Which GUI component and how?
...
I guess I need an JPanel that will contain this component that will show my files from the database. What component? Please help!
It sounds like you want to use a JTable, it has a TableModel interface that you can implement to adapt to your resultset.
Also follow the link at the top of the docs. to Creating a Table Model.
Perhaps a combined JList/JTable component would fit this need.
That is a screen shot of the GUI of FileBro.
My idea is that the JTree on the left would represent the 'directories' and table (names) of the DB. The JTable on the right would contain the data of the selected table. Change the Locate Open Edit Print buttons for Create Update Delete and the panel below that to show details of records, and it would be the start of a DB CRUD component.
Related
I'm writing Java game right now, I have a problem that I have a List which type is Ranking, with the fields name and score, and I would like to add that fields to the JLabel. Method setText() unfortunately doesn't fix. What should I do?
with the fields name and score
A JLabel is not designed to display multiple lines of text.
You can format the text using HTML.
Or I would suggest a better approach is to use a JTable, which is designed to display data in a row/column format.
Read the section from the Swing tutorial on How to Use Tables for more information and working examples.
I have a List which type is Ranking
You may also want to check out Row Table Model for an example of a custom TableModel show how you can display your Ranking object in a table.
I'm building a program that gathers a couple lists of files that match a particular set of criteria and manipulates them as it appropriate depending on the source, type of file, etc... My hope is that it will find the files and display them in a list that is easy to read. The user will select which files are going to be processed from the list, then hit a button that "starts the commotion," if you will.
Right now, I've made a class called DrawingFile that looks like:
class DrawingFile {
private static String fileName, fileType;
private static boolean actionable;
private static Path filePath;
public DrawingFile (Path path){
setFilePath(path);
setFileName(stripExtension(path));
setFileType(getExtension(path));
setActionable(true);
}
...(methods omitted to save time)...
My plan, initially was to create a JTable that populates based on a List of DrawingFiles with each of the fields in the objects being a column in the table, except the Path, which would not be displayed on the table. From there, the user would click a checkbox which would determine whether or not a file is going to be manipulated.
My issues stem first and foremost from my being relatively new to programming. This is the first program I've written that people are going to use, that also has any sort of UI.
As such my questions are:
Does my plan above make any sense at all?
Would it make more sense to leave the table out of it and create a series of JPanels inside a container? (this seems like it wouldn't be best practice)
If I do go with the table, should I scrap the DrawingFile class and store the data in the TableModel?
3a. If so, is there a way I can hide the Path in the table?
How do I go about changing the actionable boolean when it is (un)checked on the table?
On a scale of 1-10, how badly am I overthinking this?
If I understand correctly, you have a list of DrawingFile objects, and want to display this list as a JTable, where each row represents an object of the list. Yes, that makes perfect sense.
No. A table is perfect for that.
No. You should create a custom DrawingFileTableModel class, extending AsbtractTableModel, and using the list of objects as the source to implement the method. Google for "Java tutorial JTable", and you'll find an example in the official tutorial.
By making sure that isCellEditable() returns true for that column and row, and by implementing the setValueAt() and getColumnClass() methods correctly. The javadoc and the tutorial are your friends here. setValueAt(), when called with the index of the boolean column, should set its new value in the DrawingFile stored at the given row index in the backing list. getColumnClass(), when called with the index of the boolean column, should return Boolean.class.
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 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.
I am doing a proyect which is a Database Manager, I have a list at the left side with all the table names I can choose, and in the right side I have the table. The problem is that I am doing something wrong and the JTable shows like this:
Anyone can say me what does that cell values mean?
thanks
You're probably trying to display hash map values in your table. When it goes to load them, it prints the class name and not the values. Same thing happens if you try to display a JLabel or something like that without using a custom table cell renderer.
Its hard to say for sure though. Please post code and we can help you better.