I have a floorplan type program that allows the user to drag and drop items onto the plan (haven't got the drag and drop working yet). Each item has an associated labor cost and price that is stored in the object class for each item.
When the user clicks on the Get Estimate button I have a new window that pops up as in the following image.
I then want to try and format the text as in the image shown. I have the window working with a JScrollPane and the buttons. I assume when I get the items working that I will pass a reference to my array of items so that I can call item.getPrice() to get each item's cost and then display it as in the image.
What I would like to know is, what is the best way to format and display the data as shown with tabbed columns using the dynamic data?
Thanks!
If the string passed to a JLabel starts and ends with <html> and </html>, it will be interpreted as HTML.
So given the rather complex layout and style elements such as header separated with a horizontal line etc., and assuming that the table, once the window has been created, is static, the easiest way might be to use a single JLabel and format the text as an HTML table.
Related
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.
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
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.
JTable Header contains Image and on top of that image I want to place 3 buttons in a single header. My requirement is to Create a "Play List" table in which user can add their favourite songs.
So in the header I want to put a "Play List" title and "+" button to insert new playlists and "Export" and "Import" buttons.
How I can do that? Thanks in Advance.
I doubt(1) this use-case actually calls for cramming extra components into a JTable header. E.G. Take the UI of DukeBox.
We can see the play list on the left (a JTable) with a Filter text field and Random check-box above it, and the Enqueue & History buttons below.
This was created with a nested layout. The 'outer layout' is BorderLayout, that panel has the table in the CENTER, and nested panels in the NORTH & SOUTH. The NORTH panel has another BorderLayout, while the SOUTH uses a GridLayout.
If using a nested layout does not give you some ideas, I suggest you post a drawing or better, ASCII art, of the UI as it should appear at the smallest size, as well as a representation of it when it is resized (where is the extra width/height assigned?).
1) I have that suspicion every time I hear words to the effect "Wouldn't it be great if we had a component that..?". Of course, there are some classic counter-examples where the standard widget tool-kit seems lacking (e.g. a date picker or switch list), but these are common components to which a name can be put. If the person asking cannot put a 'catchy name' to the custom component, there is a good chance they are over (or under) thinking the matter.
I am displaying text data on a table for four columns(fields) . On the fifth column (field) of the table, I want to display a progressbar.
It means each individual item (row) on the table contains four different fields with text data & one field displaying progress bar.
My requirement is while uploading a file
file details(name , size , date ) are displayed for each file on a table & along with that for each file when it is uploaded , an individual progressbar also starts i.e. wrt to the specific file.
Currently am able to display the text data but the progress bar is not displayed ?
Text data is being displayed with the help of JLabel but the JProgressBar is not getting displayed on the same place . Is there any limitation on displaying the JProgressBar ?
As a side note you should note need the help of a JLabel to get the text data in the table. JTable can display that just fine with the default renderers.
Anyway, putting items like a JProgressBar into a JTable is going to be difficult as you will have to find some why to get the CellRenderer to keep painting that column to show the progress bar updates.
I think it would be easier to either:
Just use a GridLayout and several panels to add your components and progress bars.
Create a Cell Renderer that fills in a percentage of the cell with color based on the value in the cell. Then to update the progress, call setValue() for the cell that needs to increment the progress. This might not be as fancy as a progress bar, however, you might be able to use a JProgressBar as the CellRenderer component, but it might be tricky.