I am quite new to libGDX and trying to Implement the layout shown in the picture below using the table layout
The container a Table [Green] is composed of a Table header [Blue] and of a ScrollPane body [black items]. the body is also a table with various rows.
I am trying to have the body part to scroll "under" header. At the beginning all the items from body should be visible with a proper padding.
The code so far:
ScrollPane body = new ScrollPane(bodyTable);
header.add(headerBar).expandX().fillX();
container.add(header).top().expandX().fillX().row();
container.add(body).fill().expand();
[note that the required texture are not included in the snipped].
It can scroll properly but there is is like an horizontal cut header and body, while I would like to have like a rounder effect. Wonder is this is possible using tables ? Is there any example / suggestion that can point me in the right direction ?
:
I would like to help but my groin difficult to understand me well, you want it in a table for example the header remains in place, while others move buttons, for example.
http://i.stack.imgur.com/C9cwR.png
1- add window to table and table.row();
2- add other window to table and add scroller.
will not if that's what you meant.
After a bit I managed to have a working version.
In Scene2d there is the Stack widget that is design to stack one item over the other.
The overview of the hierarchy is:
Stack container = new Stack;
// the container is using all the available space
container.setFillParent(true);
container.add(body);
container.add(head);
stage.addActor(container);
The tricky part is to define the correct position of the elements inside both head and body.
So for the head in my implementation I have something like:
Table header = new Table();
Table header_container = new Table(skin);
// assign a background behind the header contents
Drawable tableBackground = skin.getDrawable("top_bg");
//some position tweaks to resize the background to the wanted height
tableBackground.setMinHeight(10);
tableBackground.setBottomHeight(30);
tableBackground.setTopHeight(10);
header_container.setBackground(tableBackground);
// headerBar is another table that contains the buttons that are in the header
header.add(headerBar).expandX().fillX();
header_container.add(header).expandX().fillX();
head.addActor(header_container);
body is a ScollPane that contains a Table. The internal table has a Top Padding defined so it is totally visible at start. When scrolling it goes under the header part and hiding a bit.
It is working but feel that there is a too much of nesting involved, if I found a cleaner solution will update the code above.
Related
How to highlight the row under the cursor when dragging and dropping?
I need to identify the row in the jtable I'm dragging onto, not the insert position which the default transfer handler supplies out of the box.
Having identified the row itself, I expect that importData(TransferSupport support) can handle the fine details.
This is a known issue in the themes for RadGridView. Currently, the ControlTemplate for GridViewRow did not have Template bindings for BorderBrush and BorderThickness. This means that the change you are making did not get propagated to the Border element that is in the GridViewRow's template. We will fix this for our official release.
However, there is a way you can do this in the current situation. You should just find the border in the template. Here is an example of how to achieve this:
var border = rowItem.ChildrenOfType<Border>().FirstOrDefault();
if(border != null) {
border.BorderBrush = new SolidColorBrush(Colors.Red);
border.BorderThickness = new Thickness(1);
}
myTable.setDropMode(DropMode....); is what I was after.
Options are:
DropMode.USE_SELECTION
DropMode.ON
DropMode.INSERT
DropMode.ON_OR_INSERT
The final one ( DropMode.ON_OR_INSERT) provided me with more than what I needed, (which is good) - the ability to distinguish between inserting a row between other rows, AND an indication of dropping data ONTO a row.
I should have done more research initially before posing the question.
I am creating a new label which I want to position precisely 130px next to an existing one. I am not familiar with layouts and would rather absolutely position my labels. My code is as follows:
playerLabels[index] = new javax.swing.JLabel();
playerLabels[index].setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/image001".png")));
playerLabels[index].setBounds(playerLabels[index - 1].getX() + 130, playerLabels[index - 1].getY(), playerLabels[index - 1].getWidth(), playerLabels[index - 1].getHeight());
panel.add(playerLabels[index]);
playerLabels[index].setVisible(true);
I am not getting any errors, but even though my labels are created. They do not appear at the desired position.
Does anybody know what I can do?
I agree that it's usually better to use a LayoutManager. That said, here's an article Oracle posted that describes how to do this:
Doing Without a Layout Manager (Absolute Positioning)
The code that you have posted will not depict the issue. Please give a sample code that can replicate your problem.
To address your problem, if you set the position of element manually (setBounds), you need to first set the container layout null and secondly you need to set the size of panel where you are adding those jlabel.
1.
this.setLayout(null);
2.
panel.setSize(900,900); // whatever the size you need.
I am building a JTreeTable. I found some starter code and have come pretty far. In the end my goal is to be able to have different data at different levels like a hierarchical list.
Currently, I have it working with data at different levels. However, I am running up against a wall when it comes to changing the columns as a next goal. From where I currently stand I have 3 more milestones:
Show different set of columns for different levels
Ability to adjust column widths for different levels
Ensure the JTree part of the table always stays to left
I am getting close to closing out this task but again stuck at the first of these 3.
Since creating a JTreeTable is complex, the minimum example leverages several class listed below in the image:
I am happy to post the code to any of those classes but I also did not want clog the question with useless code. First let me show the functionality I want.
The first image is when the top level is selected and the second image is when the second level is selected. Notice how the columns are different. That is what I want to happen in my application.
Top level selected:
Second level selected:
So one way I tried to solve this problem, is when the list selection is changed inside this section of code:
ListSelectionListener listener = (ListSelectionEvent e) -> {
TreeTableModelAdapter adapter = (TreeTableModelAdapter) JTreeTable.this.getModel();
//Need to see why this breaks.
JTreeTable.this.getTableHeader().setColumnModel(adapter.getColumnModel());
};
this.getSelectionModel().addListSelectionListener(listener);
This code is in the initialization of the JTreeTable. I have tried setting the column model on both the TableHeader and the table as well. Below is what happens then when I select a row:
The columns just disappear on me. The creation of the column model is happening in the TreeTableModelAdapter class with the following method:
public TableColumnModel getColumnModel(){
DefaultTableColumnModel model = new DefaultTableColumnModel();
for(int i=0;i<getColumnCount();i++){
TableColumn column = new TableColumn();
column.setIdentifier(getColumnName(i));
model.addColumn(column);
}
return model;
}
Any direction would be very helpful. Again happy to post any code you think could be helpful to answer the question. Just put a comment in and I will add it right away.
I will add the milestones as I find them in case this helps others, but for now this question is answered.
Milestone 1
I was actually able to solve the first milestone. The key is to trigger the creation of the columns of the column model, not to create a new column model. Below is the code for when the row selection is changed:
//Change columns depending on row
ListSelectionListener listener = (ListSelectionEvent e) -> {
createDefaultColumnsFromModel();
};
this.getSelectionModel().addListSelectionListener(listener);
This code creates the columns based on the row selected in the JTree part of the JTreeTable. The TreeTableModelAdapter implements the getColumnCount() and getColumnName() methods by also passing the selected row in the JTree to the JTreeTableModel so that the columns and their names are dynamically retrieved based on a particular node in the JTree. The key for this for me was trigger those to be called again to update the JTreeTable.
Milestone 2
Adjusting column widths based on the data level proved to be much more difficult than I had originally anticipated. In order to retain the cells state when the column model changed I had to disconnect the painting of the cells from it. This is a hairy process because this is done inside BasicTableUI and the method that gets the rectangle of the cell is private. So I had to subclass it, overload the paint() method and create my own methods that get called inside the paint method. There was a lot of copy pasting so that I could call normally private methods. I just renamed them and referenced these methods instead. The way the ui class was designed did not make it very flexible. Below is 2 images where I am selecting different levels and the columns are obviously different widths at different levels.
Milestone 3
I was able to make this work by keeping track of the view in the model. This seems very dirty to me as the model should separated from the view. Since the tree column's class is unique, I just returned the right class if that column was the first in the view.
The one problem I have with this technique is that I get unexpected behavior where the value returned is not consistent. I attempted to resolve this by overriding JTree.covertValueToText(). Since a JTree only expects 1 value and depending on the sequence of columns in the view this value could change. So in overriding this method I check the stored index for the JTree column's value. Again this causes the unexpected behavior. I will update the post if I find the fix.
I want to implement a small tooltip with a scrollbar like the one in eclipse that appears when hovering above a class or member.
The problem I have is finding a way to limit only the width but not the height of a component within the scroll pane I have inside my tooltip. The component should support HTML and also wrap the text correctly when it exceeds the width of the inner bounds, but all components I have tried out have either line wrapping or HTML rendering, but not both
A way to limit only width is also nowhere to be found as every "setXSize" where X is "preferred" "max" "min" etc. all require two arguments and there is no "setMaxWidth" method for components.
Setting "setMaximumSize(new Dimension(256, Integer.MAX_VALUE);" would seem like a solution but it doesnt work as parameters set by "max" and "min" are ignored most of the time which is quite frustrating.
On request a current example of the implementation:
public class MyTooltip extends JTooltip{
private JScrollPane scroll;
private JEditorPane pane;
public MyTooltip(String htmlCode){
this.pane = new JEditorPane();
this.scroll = new JScrollPane(this.pane);
this.pane.setEditable(false);
this.pane.setContentType("text/html");
this.scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//Here the problems begin
this.pane.setMaximumSize(new Dimension(512, Integer.MAX_VALUE));
this.scroll.setMaximumSize(new Dimension(512, Integer.MAX_VALUE));
this.pane.setText(htmlCode);
this.add(scroll);
}
}
the actual code is a bit more complex ofc. but I think this is a good approximation ...
Have you tried JTextPane with HTMLEditorKit (content type text/html)?
I think that's what you need.
Ok, the whole problem just solved itself: One had the idea to let the user write his own texts to be displayed on the tooltips, but that included letting him use multiple "spaces" for indentation when he called for it.
To let HTML render this as intended we replaced every "space" with an & nbsp; so no optimization on gaps between characters would be performed, but this of course has the result that no algorithm for automatic line wrapping would accept any "gap" between words as a suitable place to break the line.
So our implementation actually works as intended, only the Strings we give the tooltip to display are not suitable to be line broken.
Im completely new to Java web stuff, but here goes my question:
1) How can I add new controls to a JSF page (webuijsf) in the prerender() function?
2) How can I change the position of elements already added using the visual designer? Also in prerender().
I have a number of input fields + labels to show, coming from a database. So I imagine I read from the database and add the appropriate number of controls during prerender. There's also a grid below these dynamically added controls, which I'd like to move further down at the same time.
Thanks!
You would need to write your own component if you wished to render forms based on database data. You should position your grid using standard html techniques or writing your own custom grid component.