How to create something similar to JFileChooser in Java? - java

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).

Related

Creating set of JButtons according to retrieved database values

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

Grid Layout on Android?

I'm looking to create a grid layout - a complicated version actually. Since I am new at Java (I have created some Android Applications) I don't really know how to do this.
Let me explain: I want a grid layout, that looks like this:
But, instead of having pictures and colours inside of each box of the grid.. I want to have a box with 3 apps that the user can change. Kind of like the bottom part of Aviate launcher.
Like this:
So basically, I would like to have a grid layout, that the user can resize each part of the grid, each grid have a 3 apps inside, and the user can redefine those apps.
So how can I do something like that?
Thanks in advance if you understand the question.
I could not understand clearly. But, if you are looking for Gridlayout, try http://developer.android.com/training/displaying-bitmaps/index.html
Or, if you want to make a widget try open source project like https://github.com/twotoasters/HorizontalImageScroller-Android

Using CardLayout in NetBeans GUI Builder

I am using the NetBeans 7.2.1 GUI Builder. I could do all of this by hand. Instead, I am using my current project to learn how this tool works so that I can make an informed decision of when to use it in the futre (if at all).
Now with help of archived questions here, I have figured out how to change the LayoutManager to a CardLayout. I have also added three JPanels to the layout (although, there seems to be a bug...maybe a question about that later). The first JPanel displayed by the CardLayout will have two buttons. Each button will cause the CardLayout to display one of the other two JPanels. To do this, I found that I can use CardLayout#show(Container, String).
I need to know what the value of the String is for each JPanel. Doing some further research, I found that NetBeans generates a line of code such as
getContentPane().add(addCardsPanel, "card2");
So I can use "card2" to show addCardsPanel. It would be convenient to use a more applicable String. Will NetBeans allow me to set this identifying String to whatever value I wish? If so, how do I do it?
In the Navigator window select the panel you want.
In the Properties window scroll down to the Layout group. You'll see a Card Name property. Knock your self out ;)

Java Image Handling

I am trying to do a poker hand simulator. I am using Netbeans, and by the means of its GUI editor I created a JFrame in which I added the JPG of the poker table. After doing this, is it possible to dynamically add JPGs according to the hand that the player has over the poker table JPG? Is it possible to add a JPG over another? If so, how can I achieve this in NetBeans?
What I am planning to do is display all the players at the table, together with their stack and name and display their action. All this will be done with cards face up. The simulator will calculate some odds and will output some hand details in a pdf.
I want to mention that this is a homework project.
What you are after should be possible. I would recommend you take a look at the Layouts offered by the Swing Framework and once you will find what you need you can take a look here to see how you can implement the layout of your choice.
EDIT: If you are satisfied with how is your application is laid out, you should take a look at the ImageIO to see how you can load JPG images on the fly and add them to your JPanels. Usually one would use the JLabel(Icon image) constructor to add images to JPanels but there are other methods.

Java SWING - How to put my functionality under my tabs?

At the Moment I am coding my GUI, but my programm functionality flows under my tabs.
Example:
Does anybody has an idea how to fix that?
Your Layout is broken.
Try to split up component-parts (tabs and the panel content below tabs).
Add only these parts and see whether the layout of those particular components is OK.
Put everything you have into a scrollable would help you to analyse the problem and see the actual required size of your components.
Try to avoid using prefferedSize/minSize/maxSize in your code, it was not meant to layout your stuff.

Categories

Resources