How to design receipt panel in swing? - java

I have created general bill maker application on swing in which i've to print receipts as the output.
Basically i am not able to understand how can show the list of items on the panel so that it is able to print?
I am using PrintUtilities.java to print
the receipt panel.
What i am trying is to use a JTable for listing item details but if number of items is more than scrollpane viewport hieght than the rest of extra items are not shown and thus unable to print.
What can be the other way if i do not use JTable?
Or a solution with JTable itself.
What i want is to extend my whole dialog vertically if no. of items exceeded rather than using autoscrolls in JTable's scrollpane.
I hope i am clear to my question.
Here is the image of what i am trying.

I wouldn't use Swing components as printed components. Instead I'd build a PDF of the receipt and let the user print that. Scrolling is just going to be a problem with printing actual swing components that isn't easy to handle. This is a great PDF library:
http://pdfbox.apache.org/

Related

.How can I spread my text over multiple jtextpanes?

I´m building a simple word-editor in java. Currently, everything´s working fine. Now I want to create "Pages", like in word. The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it. With a scrollbar I would be able to scroll between them. So far this wouldn't be problematic. However, all the pages should belong to a single document, and if I were to delete a line on let´s say page 2, every line on every other page will be moved up. (For example) Is there an easy way to do this, or will I have to create DocumentListeners for each JTextPane, changing everything on each change? Also, is there a way to extend selections over multiple pages?
Personally I havn't tried anything as of yet, since I want some tips before writing myself into a corner. I thought that I could make the pages uneditable, and instead use a caretListener to check the position the user clicks on, to edit an invisible infinite JTextPane containing the actual document, which would write it´s content to the visible pages.
Lots of unknowns, but maybe the following will give you something to think about.
all the pages should belong to a single document,
Agreed.
The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it
Maybe add each text pane to a JScrollPane, but don't display the scrollbars or Border of the scroll pane.
if I were to delete a line on let´s say page 2, every line on every other page will be moved up
You would need to manually control the viewport of each scroll pane. The first page would position the viewport at offset 0. The next page would position the viewport at the offset that represents your page height.
Then any changes to the Document should be automatically reflected in all the text panes.
You would also probably need to use setAutoScrolls(false) to prevent the viewport from scrolling as you drag the mouse.
is there a way to extend selections over multiple pages?
Selection is a property of the text pane, not the Document.
Not sure what will happen as you try to drag the mouse from one text pane to another.
I'm guessing you might need some special logic. Maybe using mouseEntered/Exited events to trigger this type of processing.

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

Swing (Java) Category List

everyone.
I'm currently working on a project which is written in Java. As one of my features I want the application to display List of workout plans that are saved in the databases. Furthermore, I want the user to be able to click on particular instance of the workout Plan so that new JFrame is opened with further details which will be populated from the database.
You can see what I mean in the picture below, this is how I want my list to look like.
For this application I'm using Swing components to model my GUI. Its very important for me that those items within a list will act as a button so that you can open up new JFrame, but at the same time the content must be populated from database. Also when a new Workout Plan is added to the database the list must be updated and the item that will be added to that list has to be of the same format.
My question is whether it's possible to design that kind of list using Swing components, and if it is how would you do it.
Any suggestions or help will be appreciated.
I'm not that familiar with swing but, I think you can set your panel into a grid layout. Then divide the grid layout so that there are, for example, 10 rows and 1 column. Afterwards, fill the grid layout with JButton's. Whenever a button is pressed, it will open up a JFrame.
I feel like there's a better way to do this though.

Java selecting an option when clicking specific position within JScrollPane

I have developed a chat room application in Java that allows users to broadcast messages to every online user. I want to develop a new functionality that will allow the user to click on one of the online users in order to have a private chat with him/her. For this purpose I have developed a scroll-able text area that will contain those online users.
I think I could set the coordinates of each position that the name will be located at, in the text area so then when a mouse button is clicked I will compare this position against a position of the name in the string output of array list that was passed from the server (i.e. [Adrian, Buddy, Bob]).
As I have mentioned before, I am using a scroll-able text area for showing the online list, therefore I am not entirely sure if this approach would work out once I scroll down the list and click one of the positions.
Perhaps you could recommend me another approach I could adapt, or clarify if this one would work.
Here is the image of my chat client:
As I have mentioned before, I am using a scroll-able text area for
showing the online list, therefore I am not entirely sure if this
approach would work out once I scroll down the list and click one of
the positions.
Working with Scrollable TextArea for selecting items and responding with it the way you described: it will just be a hazard. Use JList with ListSelectionListener instead.
Tutorial Resource:
How to use List
How to Write a List Selection Listener

HTML gallery page in Swing with drag-drop functionality

I was asked to write a JDialog separated into left and right panel. The left panel shows a demo HTML template gallery (small sized), and right panel shows series or list of images. I want to make it such that I can drag image on the list and place it on the gallery (or maybe drag out some image from the gallery). The problem is I don't know where to start with this, can anybody give me some idea?
An HTML gallery typically uses JS to do the 'heavy lifting' (I'm guessing it will require a slideshow as well). While Swing components support HTML (to an extent) they do not support JS.
I recommend not trying to render the HTML/JS in the GUI, instead, provide a JList in the GUI of the image+name objects chosen by the user (using JFileChooser). When each image is selected, you can show the 'preferred name' in a JTextField that allows the user to edit it.
Image order can be shown by the order in the list. To change the order, implement Drag'n'Drop. See the Drag and Drop and Data Transfer lesson for more details.
You will probably need a JLabel in the CENTER of the GUI to display the (full size) selected image, and show the order & timing of the slideshow.
Once the user is happy with the image selections, the order, the names & timing. Offer them a button to write all the details to a single directory including the HTML, script & images (easier). Once the HTML is written, invoke Desktop.open(File) to display the finished product to the user.
As to how you do all that, it is really beyond the scope of an answer on SO. You would need to do the tutorial on each part, and come back with more specific questions.

Categories

Resources