For most items within Java, you simply add .setVisible(false). Then the item disappears from the form, but when I do this for a Jtable within Netbeans, using:
table1.setVisible(false);
Rather the table going invisible, it goes grey instead. Shown in picture below:
How do I get this to work?
You need to call reset() and revalidate() on the container that holds the JTable after making it invisible.
You shouldn't be making it invisible anyway, yes perhaps the JScrollPane that holds it, but not the JTable itself.
You've misspelled "Length".
Related
I'm still new at Java and having trouble at adding buttons using another JButton, the problem is that I can able to add them but right after I resize the form only. It means that the frame did not shown any JButton added to the panel unless I resize it.
right after I posted it, they already recommended related topics here and it was resolved now thanks!
just need to add 'revalidate();' at the component for it to dynamically change along the actionListener.
I am trying to implement a basic GUI where a user can move objects from one JList to another. The JLists should be contained within a ScrollPane so size is not an issue. Basic functionality is good, items will move and remove with button presses. However, the JList and JScrollPane that items are added to will display correctly and detect if a ScrollBar is necessary but do not interact AT ALL with the user for some reason. The user cannot select from the JList nor scroll the ScrollPane. Rough idea of the code below;
public void createJList(Type[] dataToList){
someScrollPane = new JScrollPane(); //someScrollPane is private global
someScrollPane.setBounds(numbers here);
this.add(someScrollPane); //this is a custom frame class
aList = new JList<Type>(dataToList);
someScrollPane.setViewportView(aList);
This is a rough idea. I also add a listener at some stage but since the scrollpane isn't working either I may as well leave that for later. I use this code for both the working and non-responsive JLists and ScrollPanes exactly the same.
Of note, I call this method everytime the list I want to display is changed. I'm thinking maybe because the JList and ScrollPane keep getting created, something is broken?
I have a DataGrid in a simple layout panel that is collapsible. It is collapsed by default, and when I expand it after the page loads, the column headers are visible but the data rows are not. If I set the panel to be expanded by default, then all the data in the table is visible, and remains so after collapsing/expanding again.
Any ideas what could be causing this? I have layout panels all the way up. I tried making the panel visible to begin with, then setting it invisible in a deferred command after setting the data provider. However, at the time the deferred command ran, the table reported having two data rows but they hadn't displayed yet. The panel was set invisible before the data rows ever became visible, so they never became visible.
I hope my description makes sense. Thanks for any advice you can give!
Calling dataGrid.onResize() after making the grid visible did the trick for me.
Please keep in mind that onResize() may need to be called from a deffered command, like this:
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
view.titleGrid.onResize();
}
});
I have a JScrollPane that holds a JTable. The table is dynamically populated from a database query. That all works fine and the table is getting populated, but its wider than the visible window.
I can see the left part of the table and I need to scroll right to see the right end of it. When I do that, the part of the table that was hidden (right end) is blurred. Then I stop scrolling and wait few seconds and then it is repainted and looks fine. I scroll back left and everything is OK - no blur.
I guess I'm missing some force repaint - but shouldn't JScrollPane handle it automatically ?
How do I get rid of this effect ?
Here is how I construct it (I wont paste all the code since it basically work):
jScrollPane1.setAutoscrolls(true);
jScrollPane1.getViewport().setLayout(borderLayout2);
jScrollPane1.getViewport().add(table, BorderLayout.CENTER);
this.add(jScrollPane1, BorderLayout.CENTER);
Never seen such an artifact, might be due to the fact that you are adding the table in a completely wrong manner. Replace the first three lines of your snippet with:
jScrollPane1.setViewportView(table);
I have Java application which adds JTextFields # runtime to JPanel. Basically user clicks a button and new JTextField is added, clicks again added again...
Each new JTextField is directly below the previous one. Obviously I run out of space pretty soon so I'm trying to use JScrollPane and thats where the hell begins, because it just doesnt work no matter what I try.
Right click on JPanel and Enclose in Scroll Pane. Didnt work.
After reading some examples I realized I must have JPanel as an argument for JScrollPane constructor. Which I did via right clicking on ScrollPane and CustomizeCode. Because apparently auto-generated code is protected in NetBeans and I cannot just change all those declarations, etc. manually. Still doesnt work.
I did try to set PreferedSize to null for JPanel and/or JScrollPane, didnt help.
JScrollPane is a child of lets call it TabJPanel (which in turn is a tab of TabbedPane). I tried to mess with their relationships, basically trying every possible way of parentship between JFrame, JPanel(holding textfields), TabJPanel and JScrollPane, but nothing worked.
I also made VerticalScrollBar "always visible" just in a case. So I see the scrollbar, it's just that populating that JPanel with JTextFields does not affect it.
When there are too many JTextFields I they go "below" the bottom border of JPanel and I cannot see them anymore.
Code for adding new JTextFields is like this, in a case it's relevant.
JTextField newField = new JTextField( columns );
Rectangle coordinates = previousTextField.getBounds();
newField.setBounds(coordinates.x , coordinates.y + 50, coordinates.width, coordinates.height);
JPanel.add(newField);
JPanel.revalidate();
JPanel.repaint();
Sorry for a long post I'm just trying to provide as much info as possible, because being newbie I dont know whats exactly relevant and whats not. Thanks in advance :)
As there is another answer now, I'm adding my suggestion too.
This sounds exactly like a problem to use a JTable with a single column. JList is not yet editable (and might never be).
JTable would handle the layout problems for you, and you can easily access the values via the table.
Use your own TableModel (a simple Vector should be sufficient in your case), and add values to it.
An option you have is to utilize a LayoutManager, instead of setting the bounds directly on the components. To test this, a simple single column GridLayout with the alignment set to vertical should prove the concept.
panel.setLayout(new GridLayout(0,1));
zero in the rows param allows for rows to be added to the layout as needed.
I do this way to add a scrollpane, create a panel and fill it with few components, then create a scrollpane in the component you want to add it, cut and paste the panel in which all your details will fall in and resize the scrollpane.Because the components take a larger space than the one visible right click on the scrollpane and select design this container, there you can increase the size of the scrollpane and add as many components as you have.