I want to create a jtable where each cell should be the size of a single character, without any separation between adjacent characters (i.e adjacent columns). There are no borders between columns so the visualization of a sequence of columns is indistinguible of a jLabel. I have tried many things like making the width of a column as small as possible until each cell is displayed as ... meaning there is no space to print the character. So say I want to have 5 consecutive cells to print the name Alice. What I have achieved so far is a table with this aspect
A l i c e
If I make the column width smaller it shows
... ... ... ... ...
And what I want is:
Alice
Thanks!!
Alvaro
What is the point of doing something like this? This will only work for a single row.
What if you have two rows:
Alice
SWITCH
The minimum width of the column will be controlled by the "W" in the second row, which means you will always have extra space around the "l" in Alice.
Why don't you just use a JPanel with a BoxLayout and then add multiple JLabels to the panel?
Anyway, if you feel you still need a JTable then you can check out the Table Column Adjuster which attempts to fit the text. The basic code would be:
TableColumnAdjuster tca = new TableColumnAdjuster(table, 0);
tca.setColumnHeaderIncluded( false );
tca.adjustColumns();
Also, make sure you use JTable.setIntercellSpacing(...) to set the Dimension to 0.
Related
My requirement is displaying a varying number of Rows in a tabelView, where each row contains a label column and a second colum,n with either a textBox, comboBox, richtext or datePicker.
The user may enter some of the values and start a search via a button, displaying the result sint he bottom half of the splitPane.
This table is displayed in a vertical splitPane like this:
Name | txtName
date | datepickerDate
gender | cmbGender
----------------------------
Results will be shown here
The number of rows of the top-table may vary from 1 to 20+.
I have fixed the maximum splitPane size to be 50%-50% distributed, if the table requires more space than 50% of the window, the user needs to scroll.
What i need is a possibility to, at runtime, know how much space the table actually needs. this is dependent on font-size and contents of the cells (eg.: a richtext-control is slightly larger than a textbox) is there a way to know the actuall space the tableview is going to need?
All question i found here relate to fitting the tableview to the window-size, i need it the other way round, i need to place the SplitPane separator where the table ends
Thanks in advance,
BillDoor
I'm looking for a way to get the number of characters that can appear in a row in a JTextArea.
I tried using getColumns() but this returned 0:
jTextArea.getColumns();
Does anyone know how this can be achieved? I need it so that I can display data in fixed width columns, so I need the number of characters that can fit in a row in order to calculate this.
If you don't specify number of rows and columns when creating JTextArea, it default the rows and columns to zero. This mode allows the JTextArea to expand/contract according to available space for itself and actual number of letters shown in a line etc can be adjusted.
In the default mode, the number of letters that would fit in a line will depend on the current dimension of the component, the line wrapping style (word boundary or character boundary) and the font used.
If you cannot set the row, columns in the JTextArea then you can probably use javax.swing.JTextArea.getColumnWidth() to get the size of one character and use the current width of the component to get approximate number of letters that will fit in a line.
I want to create a table looks like
this.
but the only way to to this is with an horrible merge of cells.
i try to make two separate table but the top table, follow the cell width of bottom table like this.
There is a way to make an asymmetric table without merge cells?
You don't have to 'merge' cells, but you do have to tell it how many grid columns or rows the cell spans. Picture a grid that has a column that matches every column position, and a row that matches every row position. In your example, you would have a grid with 18 columns and 3 rows. Then for each cell that spans one or more grid column or row, you must have a span attribute that tells how many grid positions are spanned by the cell. The result is the same as merging, and it might even be what you meant by merging, but that is the way the spec reads.
I Have a JTable (or a JXTable to be more precise) with 3 sections of grouped columns I want to divide.
I used to have 3 tables which i programmatically linked (the scrollbar position, the sorting, the selection). I used a lot of code to get this linked, and I want to get rid of this.
Now I Am switching to 1 JXTable, because there are some things a lot nicer in this table class.
I found some (not very satisfying) solutions to almost the same problem.
Maybe some one has a good suggestion for me.
Option 1: an empty column as a divider (another color, like gray) and programatically hop over this empty column when using the arrows or tab keys.
option 2: setting the margin for just 1 side of 1 column to a larger size, so it seems like a divider. Untill now I have only found out how to set the margins for all columns
option 3: getting back to 3 seperate tables again (especially to get the tables sorted in the same way is a lot of work, because I do not want to repeat the columns in the seperate sections). This means I have to rewrite my table sorter, sorting on a non-visible column.
any suggestion is welcome (also if it's none of the three given options)
I've made something that looks somewhat like what you're going for by overriding the cell renderer on the 3rd column to have a thick right border and no other borders. You could do the same within the table column header to have the border extend up through there. It's clearly placing the border within the cell but this may be sufficient for you.
{
....
table.getColumnModel().getColumn(2).setCellRenderer(
new ThickRightBorderCellRenderer());
....
}
private static class ThickRightBorderCellRenderer
extends DefaultTableCellRenderer {
#Override
public Border getBorder() {
return BorderFactory.createMatteBorder(0, 0, 0, 3, Color.BLACK);
}
}
I'm working in Java using the Vaadin framework.
I have a table with 14 columns. My problem is that that there's a small gap to the right of the last column, like the beginning of a new column that shouldn't be there..
The image shows the problem:
I've tried solving it with using column expand ratio on the last column, but this makes it abnormally big..
Do any of you know of a property you can use, CSS or Java, that makes the columns stretch over the entire width of the table without causing large column disproportion?
This is known issue, it was closed already Ticket #6677
If you set your table to fullsize that should probably close the "gap".
YourTable.setSizeFull();
I gues you ahve your table in a layout. Set this layout margin to false and also remove spacing.