Extended JTable clipping problem - java

Hi I'm using set of classes I found on internet that extends JTable capabilities making me able to merge or split some cells.
Mentioned capability works ok but I have two problems with how the table is displayed. The extended JTable is stored in JScrollPane and it is stored in Box.
The first issue is that when I have a lot of collumns the last one or last two ( depends on how many collumns I have ) is being clipped ( when I move scrollbar to the right edge I don't see last collumn or it is clipped so only the part of the data is visible.)
I did some experiments and I add some empty collumns and that helped so I assume it is something connected with how JScrollPane gets the width of the table it should display but I could not figure out how can I change that. I was trying to call table_.setPreferredScrollableViewportSize(new Dimension()); with Dimentsion set to something really big but it did not help.
Second issue is that when I click on a cell that is placed closer to the right edge then the next cell is being selected. The further the cell is from the left edge the further cell to its right is being selected. I can't see selection when I click on the cell from last collumn.

If there is no easy answer maybe someone knows some open source alternative to display data in table with merging capabilities. I found only commercial ones which cost a lot of money.

Related

Jtable losing multiple row selection,when button in one of the column is clicked

I have a very basic problem with jtable. I have a jtable that has multiple columns with one of column having a button. When i click on that button a panel drops, and asks to select an option from given options. When i select that option, value replaces in one of the column.
Now, i want when i select multiple rows, and do the same thing as above, it should replace that column in all the selected rows.
Problem: Currently, my table is losing selection when i am clicking the button in one of the column in jtable after multiple row selection.
I searched google and stackoverflow a lot, but could not find anything meaningful. Anyhelp or sample code is appreciated.
Thanks
If I understood your problem correctly then the solution is fairly simple.
First of all the issue probably occurs because once you click on the button java sets a new focus on the button and therefore clearing the focus on the other rows. That won´t be a problem in a single selection because you still click into the selected row, however doing that with multiple rows in one go won´t work that way.
To solve this you need to save your previous selections in something like an ArrayList and after the whole option thing you can apply the changes to every element in the ArrayList and reload the table.
A cleaner and more intuitive approach though would be to place the button outside of the JTable.

GridBagLayout: changes alignment after adding checkbox

I have two classes which creates two different dialog box. Both the classes have same code, except one has additional lines of code, which creates a checkbox
first Class, with Checkbox
Second Class, without Checkbox
There is slight alignment difference in "save" button. How can I fix this.
Is there a particular reason you're using fixed row and column sizes? One of the great features of GridBagLayout is its ability to center/align and fill. This also tends to make things look better on different screen sizes, different fonts, etc.
To answer your specific question, my guess is that the checkbox is taller than the row you're putting it into, pushing the next row down.
When I debug GBL, I often set row/column background colors to different things and print out (or view in a debugger) sizes of the things I'm trying to fit into the container.
I had to adjust the row height as the checkbox was taller than the row and was pushing the third row downward( Thanks to Ingrid Biery). so I changed the 2nd row height from 25 to 30 and it worked.

Can you set the cells of JTable to spill over?

I'm trying to imitate some Excel spreadsheet functionality on my JTable, specifically what I've been calling cell spillover or cell overflow. This occurs when you fill a cell with text with a wider width than the cell is set to. If there is no text in the cell to its right, the words simply keep going into the next cell and beyond.
I feel like this would be accomplished somehow with TableCellRenderer, but I do not know how.
Any help would be much appreciated
I dont know because you did not give alot of detail but a simple use case would be:
When text is entered check for the amount of characters
Check for the width of the cell and look if the text fits
If the text doesnt fit check if the cell next to this one has text
If it has no text, resize the cell to fit the text and make the one next to it smaller.
Or something like that.
But i dont know if JTable allows resizing of individual cells, you should check the JTable API.
http://docs.oracle.com/javase/6/docs/api/javax/swing/JTable.html
And i dont know if there is not a better way, so you should consult API documentation and examples.
For example: http://users.csc.calpoly.edu/~jdalbey/305/Lectures/TableCellRendererExamples.html
I hope it helps you.
No, a TableCellRenderer cannot span cells. As alternatives, consider these:
TablePopupEditor, a custom TableCellEditor, can be adapted to serve as a renderer.
A ListSelectionListener, shown here, can be added to an adjacent component in order to display details of the selected row, perhaps using a JScrollPane.

GWT Celltable fixed columns

Is there a way to make, let say first 3 out of 7, columns fixed in Cell table. I want to be able to see always first three columns and have horizontal scroll on others.
You will have to create a custom widget that consists of a ScrollPanel, which includes two CellTable widgets set side by side. The right table should be wrapped in a FlowPanel with overflow-x property set to AUTO (overflow-y should remain at HIDDEN).
You can use the same DataProvider for both tables to synchronize all changes. Be careful with the SelectionModel though, if you need it. I would limit selection to the first column of checkboxes and disable selection by clicking on a row.
Make sure that your widget fits into its space, or you may end up with two horizontal scrollbars - one for the ScrollPanel and one for the right table. Finally, remember to set sizes on both tables so that they have the same height.

set scroll bar position in JTable/SWT Table

I would like to ask question that is not directly related to any technology but it’s a logic level question. Forgive me if I am wrong.
I am trying to solve this issue in Java side.
We have a list view (may be JTable or SWT Table). We are displaying records from a table in to that list. The table may have millions of records. And the table size is keeps increasing. As the table size is huge and it keeps increasing we are keeping a cache of 3000 records and displaying the cache in the table. So at a single point only 3000 records will be there in the view. At this time, the scroll bar of the view (JTable or SWT Table) shall be set based on the cache only (in this case 3000 records).
And based on the user events like, PgUP, PgDwn, DownKey, UpKey, Mouse Scroll etc we are refreshing the cache so that the view will be refreshed.
But we need to give users an actual feel that the scroll position based on the records in the table. I think it is not possible as the scroll position is set by the OS based on the number records in the display. Can somebody can assist me with an alternate method. If I am not explained my question correctly, I will explain this in details. Please help.
Usually a scrollbar is set at the top of the list, or at the bottom, depending on if the property "AutoScroll" is set to true or false.
I believe there IS a method where you can set the scrollbar at a specific point, but last time I tried using it, it was kinda clunky.
It sounds like you're trying to make the scroll bar do two things at once, and that can be confusing. You could use a separate control to the do the paging. A row of buttons in a JToolBar looks nice, but a JComboBox will take up less room. There's some good answers about this here.

Categories

Resources