First of all, I'm using Swing in Java. In my application, I need to have a multi column list (if that's what I should call it). What I mean by a multi column list is something like windows explorer's list view mode of showing files and folders.
So, all of the columns of my list are going to have the same object (files for instance), but I want to be able to put them on different columns, in order to have a wider view.
Does anyone have any suggestion how I can do that?
Thanks,
Reza
One may use:
list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
Alternatively you can use a JScrollPane. This will handle creating scroll bars and such for you, which would solve the issue of running out of vertical space, and thus eliminating the need for extra columns.
Related
I'm working on a POS system for a fast food restaurant. I've developed Adding, updating and deleting products using a MySQL Database. Now I need to create the POS GUI (using SWING) which the cashier uses to create the bill. The interface I have in mind is like what MacDonald's uses, there's a set of buttons with the product images. (I have stored BLOBS of products successfully)
example image :
I have no idea on how to accomplish this, it would be awesome if its possible to generate a set of dynamic Jbuttons which gets the image of a product along with the name and price. Is this the best way to accomplish this? and how do I achieve this? A few details to put me on the correct path will be greatly appreciated!
Thanks.
You have at least four containers, the top row, the bottom row and each row containing a separate container in the middle (for the buttons).
The basic layout for the rows might be a GridLayout, each row would probably use a BorderLayout with the nav buttons in the WEST and EAST positions. CENTER container could use a GridLayout, but won't give you the look you're after. You could use a FlowLayout and even a GridBagLayout, but you'd need to ensure the size of the buttons where correct for your needs
On the left I see a JTable and two JPanels, containing the buttons, held together with a GridBagLayout.
On the right I see a JList. See How to Use Lists for more details. You'll probably also want to have a look at Concepts: Editors and Renderers and Writing a Custom Cell Renderer for details about how you could customise the look of the cells and How to Write a List Selection Listener for details about how to determine when the user changes the selection
Together, they are probably maintained by a GridBagLayout within a single container for ease of use
Along the button is probably another container using a GridBagLayout.
Altogether, they are probably held together by a GridBagLayout
Have a look at Laying Out Components Within a Container, How to Use GridBagLayout, How to Use BorderLayout and How to Use FlowLayout for more details
You will need to look into the GridLayout.
In your case, it might be a little bit more complex since you have multiple grids, some of which seem to be nested within each other.
You should be able to allocate the grid dynamically and then leave it to the layout manager to distribute things evenly over the page.
Depending on the complexity of your layout, it might also be a good idea to look into the GridPane provided by JavaFX.
Hi I look for you this problem and I find this solution ;
http://www.javasrilankansupport.com/2012/06/create-dynamic-jbutton-with-image-and.html
I'm working on my first java program. I'm making a Project Manager program.
The base idea is that i have a JList which contains the names of the Co-workers. If you double click one of the names a JTabbedPane will pop up a new tab and will be populated a JTable what is containing the specific persons tasks.
And here comes the tricky part. I want to use this JTable to modify the datas so i need to give a specific name to the JTable so i can use that later on in my methods to call it.
The question is how can i create dynamic names to these tables so i can call it later (something like this: table+tabID).
OR
Is there a better solution to my problem?
Any help or advice is greatly appreciated.
I solved it. The solution was:
I made an ArrayList<JTables> to store the tables and I'm using the tab indexes to get the proper table.
I am trying to make a frame similar to a JFileChooser. I have a scrollpane and 2 toggle buttons, one for list view, and other for icons view. I will be using CardLayout on the scrollpane. However, I don't know where to begin. I would like to know a good approach on this matter. How do I design the 2 panels that will be put over the scrollpane?
Something similar is the GroupBox in C# forms.
If you want to create "something similar to JFileChooser" why not to take a look on code of JFileChooser itself? You can find JDK source in file src.zip under your JDK directory.
See File Browser GUI for some tips.
I need to know how to create custom views. For example, for the listView option, I will be able to create a Jlist(i think) that will be spread out horizontally on multiple columns. For iconsView i will have some thumbnails that will be displayed vretically on multiple rows, etc.
For the detail view I'd tend to use a JTable. 'horizontally in multiple columns' can be done using a list and setLayoutOrientation(int).
Hi am creating an application in which I am using JTable to listing of file or folder names.
My question is:
How can I find and Search a Particular file or folder in JTable like in Windows.
In windows directory listing when we press any key then we can see that file or folder start with that character is selected and if we again press same key then next file/folder is selected with start with that character.
If you can use 3th party code, I would suggest to take a look at the SwingX project. Their JXTable, JXTree, JXList and some other classes provide an implementation of the Searchable interface, which makes creating a search widget a breeze.
And if that is even too difficult, they provide out-of-the-box a JXFindPanel which provides a UI to search a Searchable
If you can (and you're willing to) use third party UI components, the Open Source JIDE Common Layer offers a few nice components: e.g. you might like FolderChooser which has an automatic find-as-you-type functionality.
Here's the link: JIDE Common Layer. If you click the "RUN IT" button you can see a sample via Java Web Start.
I've used many JIDE components (only the open source ones) in my projects and avoided reinventing the wheel many times.
Hope this might help you.
You want an action happen when a key is typed ?
-> add a keyListener to your table
You want to know which row is valid
-> query your datamodel connected to your jtable
You want a selected row to change ?
-> in the keytyped implementation of your listener change the selection
table.getSelectionModel().setSelectionInterval(1,1);
Since I don't know something about how did you implement your code logics, JTable implemented Sorting and Filtering
but you describtions talking about JTreeTable
I would consider writing a custom TableCellRenderer, responsible for highlighting any matching letters in the String being rendered. When someone updates the search text field the simplest approach is going to then be to repaint the entire JTable to show the updated "match state" of the table cells.
I'm looking for a Swing component that displays several separate strings (probably from a string array or list) on separate lines within a pane or field (scrollable if there's too many to show at once). The user needs to be able to select one of these lines (double-clicking would be ideal) and thereby trigger a listener that does some magic with that line's string. Can anyone point me in the right direction?
Try a JList: http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JList.html. Can be added to a ScrollPane if you want to include scrolling ability.
I suggest you to use a JList inside a vertical JScrollPane.
The user needs to be able to select one of these lines (double-clicking would be ideal) and thereby trigger a listener that does some magic with that line's string
You can use the List Action for this.