In my project i need to draw a facility plan.
I need to draw table made from squares and i tought i can make it with JTable component.
But there is one more thing i need:
I need to set different borders every cell but also i need to draw border to different sides of cells.
Here are my questions:
Is there any way to process every cell different?
Is there any component to do this?
Or is there any options to do, without jtable?
thank you so much.
regards
Check out Table Row Rendering. It gives an example of how you might customize the Border for all cells in a row. You should be able to customize for your exact requirement.
Related
In Grid component when I try to resize frozen column too much it goes out of the grid and there is no way I can resize it back to its initial positionThis is an example from Vaadin sampler.
Is there any way I can prevent frozen columns from extending out of the grid?
I tried to call setMaximumWidth() on frozen columns however this seems to not work on columns that are being resized.
Sounds like the manual column resizing is not respecting the maximum width, so it's a bug in Grid.
button[currRow][currCol].setBackground(Color.RED);
button[currRow][currCol].setContentAreaFilled(true);
button[currRow][currCol].setOpaque(true);
That's what I have right now for my connect four game to denote a red player's move.
At the moment, it only colors the background and if I change my code to button[currRow][currCol].setForeground(Color.RED) then the whole thing just appears to not change. How would I fix this?
This is not easily achievable. The problem is that the pluggable look and feel paints the button content, and it does so in whatever way it sees fit. For instance, some L&F might paint a gradient which does not use the background color.
I suggest for a case such as yours to use a custom image (JButton.setIcon()) and no content area (JButton.setContentAreaFilled(false)).
Alternatively, you could create a custom component which draws the element itself, overriding JComponent.paintComponent().
I need to add a picture (see below) and change the colors of the cells dynamically (it will depends on a dynamic content of JTable).
I was thinking to load this picture as a background of a new JTable, however in this case it's difficult to fit JTable's cells to the cells in the picture.
Another idea is to load image icons of blue colored squares into each cell of JTable, and then dynamically change these image icons by another ones.
So, what is a good solution for this kind of problems?
Everywhere I look for help with GridBagLayout only helps with GridBagConstraints. I understand that part completely, it's the methods inside GridBagLayout that confuse me.
So I realized that the fields columnWidths and rowHeights are for overriding GridBagLayout's cell widths and heights, and are null until set by user. (I have implemented those fields in my program below) So how do I get the ACTUAL width and height of the cell?
I'm basically trying to override the paint method of the container in order to draw a grid that show where each cell begins and ends (where gridwidth and gridheight is irrelevant). The one thing that looks applicable is getLayoutInfo(Container parent, int sizeflag), but GridBagLayoutInfo has no methods or fields, and I have no idea what it means by sizeflag.
EDIT:
This is basically the grid I would like to draw, but of course I want to make sure it would work on any container where gridlayout is the layout manager. These are the actual gridx and gridy coordinates highlighted in red. I just don't know how to get the values I need to the paint method.
GridBagLayout has a method getLayoutDimensions() which returns array of two arrays. First array is column widths and second array is row heights. This method considers insets set in GridBagConstrains of each cell to be part of the cell.
I know this question is stale but I ran into simmilar problem recently and found it while searching for solution.
How can I calculate the dimenstions of the cell in JTable containing various components to calculate the height of table dynamically.
For example, I have a table containing multiple checkboxes in the 3rd column and various components in other columns. When new components are added to the cell, then the height and width of the whole table should change dynamically.
Thanks in advance.
You might be able to leverage the approach shown here, which invokes setRowHeight() to accommodate the maximal height of each column's renderer.