i have a little problem to layout a TableView inside a ScrollPane :
i want to know how to make the TableView always fit inside the ScrollPane, What happen is :
when i make the windows small everything work good there is a scroll bar and that work
but when i make the windows larger the TableView don't grow with the ScrollPane, so how to make it work, i have tried to set fitWidth of ScrollPane to true, but if i do the TableView Column are just resized with the size of the window there is no scrollbar
If you are using scene builder to construct your fxml, it's very easy to do this. Just select the scrollPane which wrap your tableview and check option "Fit to Width" in Layout. However, you can also do the same work in code by checking your scrollpane object but not tableview object.
The solution is to put TableView in UNCONSTRAINED_RESIZE_POLICY mode
Related
I use in my app a JscrollPane with a BoxLayout panel inside. I it to never change value after repainting. How can I do this?
I tried
pane.getHorizontalScrollBar().setValue()
but it doesn't change anything.
You could try setting the Horizontal (and/or) Vertical scrollbar policies:
pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
You could also mess around with the Viewport's size (max & mins), etc.
Found solution.
Now I repaint panel inside scrollpane instead of scrollpane and it works.
The problem
In code it works perfectly if i do it like:
TilePane tilePane = new TilePane();
ScrollPane scrollPane = new ScrollPane(tilePane);
I mean that every time the TilePane has more items that can be shown then a scroll appears vertically or horizontally without adding any extra code or setting minimum or preferred size of TilePane.
Using SceneBuilder
Instead of using pure code i want to have the same result as the above using SceneBuilder but every time i am trying to do it something like this: happens
I have to set the preffered size to the TilePane.Why thought? And it doesn't work as expected.I want it to automatically work as described in the first lines of the question.A good description is needed...
See the prefWidth and prefHeight to USE_COMPUTED_SIZE. These are the default values for a TilePane, but SceneBuilder seems to set them to default numeric values when you drop the TilePane into a ScrollPane.
You can select these values directly by clicking on the drop-down boxes next to the text field for the prefWidth and prefHeight text fields.
So I've been searching around and for the life of my cannot figure out how to correctly do this. I simply have a small text area and want to be able to scroll through it. I've been told it's as easy as adding the TextArea to a ScrollPane, but it appears to be more complicated than that. Here's the gist of my code:
Skin defaultSkin = newSkin(DEFAULT_SKIN_FILEPATH +"uiskin.atlas", DEFAULT_SKIN_FILEPATH
+"uiskin.json");
TextArea textArea = new TextArea(levelLoader.getCodeSnippet(), defaultSkin);
ScrollPane pane = new ScrollPane(textArea, defaultSkin);
pane.setForceScroll(false, true);
pane.setFlickScroll(false);
pane.setOverscroll(false, true);
pane.setBounds(0f, 20f, game.getWindowWidth(), 300f);
gui.addActor(pane);
Gdx.input.setInputProcessor(gui);
setIsCreated(true);
levelLoader.getCodeSnippet() returns a string containing a multi-line piece of text from a .txt. The TextArea appears in the game window, and the multi-lined text also appears. However, I can only scroll through the text with the arrow keys. I forced the scrollbar to display itself, but it occupies the entire right side of the window like this:
http://s27.postimg.org/vqws36k77/pic.png
It will not scroll and thinks there are not multiple lines to scroll through even though there are evident by scrolling through with the arrow keys. I've also tried making the textArea larger than the scrollPane, but might have done it incorrectly. What am I doing wrong here?
Update: I've tried both placing the ScrollPane inside of a table and setting the cell size of the table. Any other suggestions would be appreciated.
This is not best solution. I guess it is LIBGDX update layout bug.
This is workaround solution that works for me:
Set pref. rows manually and update scroll layout, when the number of the rows is changed.
textArea.setPrefRows(numberOfScrollLines);
//numberOfScrollLines = text.split("\n").length
pane.layout();
I am trying to set preferred width for jscrollpane in borderlayout(WEST).but it is not working
Please look into my sample code
JTree tree=new JTree(root);
JScrollPane jsp=newJScrollPane(tree);
jsp.setBounds(0,0,200,100);
Jframe.add(jsp,BorderLayout.WEST);
but it is showing default width.
Alternatively I tried to set preferred size for JTree , it is working fine but jscrollpane is not working properly.Please help me in this.
It is the layout manager who determines the position of the component, based on the sizes of the component (minimum/maximum/preferred). So your call to setBounds will be ignored and instead the BorderLayout will determine where it places your component.
Normally this mechanism works just fine. The problem with a JScrollPane is that its size hints might not be in sync with what you want as behavior (due to the fact the scroll pane can have scroll bars, so it can determine its own size).
Solution: just call setPreferredSize on the JScrollPane before adding it. This is also done in the official tutorial and about the only time I can think of that it is acceptable to call this method.
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.