Problem displaying Progressbar on Applet - java

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.

Related

JScrollBar doesn't update its maximum value after JTable changes

I have a JTable that when clicking on the row expands it and filters all other rows in the table. When the user clicks on this expanded row again it returns to its normal size and the filter shows all the table again. All this works fine but when returning from the view of a single expanded row to the whole table I would like to set the scroll pane vertical scroll bar value to that one which is the position of the row that have been expanded. I correctly compute this value and try to set it with
scrollPane.getVerticalScrollBar().setValue(value);
but as I have found with scrollPane.getVerticalScrollBar().getMaximum() the scroll bar doesn't update its values after sorter.setRowFilter(filter); invocation. getMaximum() returns the height of that single row that have been expanded and for that reason scroll bar fails to set the updated value (that is typically much greater). This is the code:
// after this call the table shows all its rows again
sorter.setRowFilter(filter);
System.out.println("maximum=" + scrollPane.getVerticalScrollBar().getMaximum());
// shows old value when the table has consisted from a single expanded row
scrollPane.getVerticalScrollBar().setValue(value); // fails
Can anyone tell me how to let the scroll bar to know that the view of JScrollPane has changed so it can correctly set its maximum value? (though the scroll bar itself seems to be ok and looks like it has look properly scrolling all table). I have tried to call revalidate and updateUI methods on the JTable but it doesn't help.
scrollPane.getVerticalScrollBar().setValue(value);
Try wrapping the above code in a SwingUtilities.invokeLater(). This will add the code to the end of the event queue.
You need to revalidate the JScrollPane, but only after you invalidate the JTable. Thus, something like
sorter.setRowFilter(filter);
sorter.invalidate();
// shows old value when the table has consisted from a single expanded row
scrollPane.revalidate();

Can JTable be resized by the user dragging the mouse

So I am creating a GUI and it has a JTable that is set inside of a JScrollpane. When the user opens the window it displays everything how I want it to. The user can add rows to the table to fill in data and then they can scroll through the information. I also have a JButton which I have set to print the whole window. Now my problem is the table prints but only shows the data in the viewing area. What i was thinking was if the user could drag the bottom corner of the JTable to re size it to show everything then everything would be ok, I'm just not sure if that's even possible or how to do it. Ive been searching and i haven't seem to come across anything like this yet.
Edit:
So for anyone else here is the link to the class I found. It allows you to use the mouse to resize any component.
http://tips4java.wordpress.com/2009/09/13/resizing-components/
To get an image of the entire table you can try using Screen Image, which allows you to take an image of a specific component.

How Do I Format Text Like In The Linked Photo?

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.

java swing jtable screen location of cell renderer component

I'm new to swing and I faced my first serious problem, here goes:
I have a JPanel with JTable and lots of checkboxes below the table. I'm trying to align the checkboxes below the table with checkbox located in the first table column. The problem is - this has to be done when model data changes.
Immediatly after the fireTableDataChanged() gets triggered in JTable there is no way to get the screen location of its custom cell renderer component (which in my case is JCheckBox).
As far as I understand this happens because JTable gets redrawn asynchronously. Whenever I try to get the location the IllegalComponentStateException gets thrown.
Any ideas on this are highly appreciated.
You shouldn't do it manually. You should use the appropriate layoutManager. Check this link for the different Layouts:
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html
This might help you to get screen location of row and column.
Rectangle rect= cartTable.getCellRect(row,column,true);
//cartTable-Jtable object name
int x=Double.valueOf(rect.getX()).intValue();
int y=Double.valueOf(rect.getY()).intValue();

Multiline feature in an editable jtable cell

I want to have multiline feature for JTable cells. Wherein the cell automatically expands and shrinks itself when user writes or deletes text in/from cell. I have set columns width, but it doesnt automatically adjust itself according to user's input, rather text beyond the width are not seen at all, but i have a requirement to fix on the width. Can anyone help me with this, to have self adjusting and multiline feature for jtable cell. Would be very thankful.
Thanks in advance.
Several steps:
implement a custom renderer using a JTextArea as rendering component
implement a custom editor using a JTextArea inside a JScrollPane as editing component
add logic (aka: TableModelListener) which updates JTable's individual rowHeight based on the renderer's preferred size on receiving a change notification

Categories

Resources