I have a GUI with a few JTextFields and JTables, and I would like to get the possibility to dynamically re-size the tables after running the application, so the user can increase the size of the tables by clicking on the border and dragging it.
I am considering this option or this post, but not sure if that´s what I need.
JTables are combined with table scrollers, and the GUI uses a JPanel with JGoodiesFormLayout, since it makes very easy to work with rows and columns.
Use JSplitPanes to divide the GUI where you want to allow the user to specify the component limits.
Related
I want two or more tables to be shown/overlapping each other.
Currently using netbeans
I'm using jFrame form so not manually creating a layout.
Can this be done?
Its possible using null as the layout manager (absolute positioning). You might also want to place each table in a separate JInternalFrame container as this will allow you to move and resize the tables freely withing the main window.
I am using a JTable in a program. The problem is that when I set the size of the whole JTable, I am using this method:
setPreferredScrollableViewportSize(Dimension size)
The question I have is that when using this method, you enter in the width and length in pixels. Will there be issues (formatting-wise) when the program is run on different computers/machines?
Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing? - Short answer is yes (you should avoid it)
When setting the preferredSize of the table, you are not actually taking into account the number of rows or columns which the table might have, depending on the layout manager, it may NEVER be larger than the dimensions you provide, regardless of the amount of data
The question I have is that when using this method, you enter in the width and length in pixels. Will there be issues (formatting-wise) when the program is run on different computers/machines?
Generally, yes.
JTable was designed to be shown within a JScrollPane, which allows you some leeway with this, as the JTable can grow and shrink, within the JScrollPane, but the JScrollPane can remain the same.
Having said that, you should NOT be using setPreferredSize and especially not messing with JTables, JTable calculates it's own preferred size based on the needs of the data...and it does a reasonably good job.
If you want to change the size the JScrollPane, then you will need to change the result of getPreferredScrollableViewportSize which lets the JScrollPane know how big a component would like the basic viewable area to be, under optimal conditions
See How to Use Tables and How to Use Scroll Panes
I'm designing GUI using java swing with the help of windowbuilder. I found that in any layout it's not possible to resize components by using mouse drags (even though it shows points to pick and drag to resize). Specifically reducing size is what most important to do.
Resizing is allowed only in two layouts: one in Absolute Layout (which is not at all good for practical purpose, considering different screen-sizes with which GUI should be better displayed) and another is Group Layout (which is also not a good for design due to it's complex code).
Following is the sample where I have placed two JLabels and now trying to add JComboBox at the location indicated by Green box.
But when I place the JComboBox it's default size is to fill horizontally. Even if I change fill to 'None' and try to resize, I'm unable to resize it. Following is the result after addition of JComboBox:
In the Background there is JPanel with GridBagLayout with following properties:
I found that changing values in columnWidths and rowHeights properties of GridBagLayout, the size of grid columns/rows can be controlled. But I'm unable to understand Size of which columns/rows all those values represents?. (I found no direct relation between number of those values and number of columns/rows displayed on Panel)
Is there any way out to resize components? And can anybody explain what those values in columnWidths and rowHeights properties of GridBagLayout represent?
It's simple, you need to add grow in you WindowBuilder. It looks like this:
picture
Click on this with your right mouse button and click on 'grow':
picture
Only objects with 'grow' are resizable.
I'm trying to write a scorekeeping app in Java that allows a server application to send scores to client applications. The clients will then display a list of teams, team IDs and their scores, sorted by score. Of course I could just use a swing JTable to display everything, but I want to achieve a unique effect: I want the text dynamically reorder itself every time a team moves up in the list. That is, it want to animate the text around the screen. I would also need to be able to update the contents of the labels after being added. What would be the best way to achieve this? Is there any component that allows you to add other components to it and place/move them freely?
JTable is a JComponent so you can set desired LayoutManager and add JLabels above the JTable. Then move/reorder them to achieve desired effect. See SwingWorker as well.
You could use a JTable and change the contents of the rows as teams move up. Or you could arrange a series of labels and change the text whenever you want. To change the value displayed for a JLabel you simply use the JLabel.setText("new value"); method.
I've never done this but I think you need to use a panel with a 'null' layout manager. Meaning you are responsible for absolutely positioning your elements
http://docs.oracle.com/javase/tutorial/uiswing/layout/none.html
You would need some kind of SwingWorker or Timer running to update the gui layout. Make sure you actually make the GUI changes on the EventThread, which you can do by using SwingUtilities.invokeLater();
As alternatives to a null layout, consider letting the layout work for you using
one of the marquee effects discussed here, or
shuffling labels in a suitable layout, shown here and here.
I would like to create an interactive JTable. For this, I would like to add JPanels in the cells of the table. Once the JPanels are in the cells, I can add my various components to the JPanels thus making the table interactive. Each JPanel could have different components. Would it be possible to accomplish this and only have to create 1 table cell editor and 1 table cell tenderer. Does anyone know of a better way to do it?
Thanks
EDIT: Thanks for the responses. I actually already have a framework I am using. I just needed a JTable that users could drag and drop images in, play movies, display graphs, etc... I already have the functionality to do those things, I just needed a JPanel to add them too. I wanted it to be displayed in a JTable so the cells could be sorted, moved, add/delete rows/col, and well structured. I couldn't get it to work using the JTable, so I went ahead an created my own. Its just a JPanel that contains smaller JPanels (the table cells) using the GridLayout. It works well enough for my puposes. Just a pain to rewrite all of the functionality from scratch that a table has.
This is hard. JTable actually uses the cell renderers only for painting the cell content. I would recommend to check if a gridlayout packaged into a scrollpane would be the easier solution.
It sounds like you're trying to use JTable as a docking framework. Assuming this is the case you're better off using something like MyDoggy or JDock which allow you to decompose your GUI into multiple split pane areas.
JSplitPane may be an alternative in this context: one pane would hold the JTable, while the other displays expanded details of the selected row. A compete example using GridLayout is shown here.