I'm trying to add label here
Label missionTitle = new Label(mission.title, skin);
Label missionDesct = new Label(mission.desct, skin);
Label remainDay = new Label(TaskManager.getRemainMissionDay(mission.deadLine) + "day remain", skin);
missionDesct.setFontScale(width * 1.4f / 1080);
remainDay.setFontScale(width * 1.2f / 1080);
missionDesct.setWrap(true);
Table table = new Table();
table.debug();
table.background(new TextureRegionDrawable(new TextureRegion(new Texture("image/imgray.png"))));
table.add(missionTitle).width(width / 1.1f);
table.row();
table.add(missionDesct).width(width / 1.1f);
table.row();
table.add(remainDay).width(width/2.3f).left();
for that i'm adding this lines;
Label goldLabel = new Label("30 gold", skin);
table.add(goldLabel);
But result is;
this
How can i add a new cell over there?
I tried to adding ".width(width/2);" but it's not working.
...
table.row();
table.add(remainDay).width(width/2.3f).left();
Label goldLabel = new Label("30 gold", skin);
table.add(goldLabel).width(width/2.3f);
You can do that by creating a table with the 2 labels and then adding the table into the container table.
Example -
Table nestedTable = new Table();
nestedTable.add(remainDay).width(THE_WIDTH);
nestedTable.add(goldLabel).width(THE_WIDTH);
mainTable.add(nestedTable);
You can play around more with this to get the desired result :)
This class can also help - HorizontalGroup
Finally i understand my mistake.I was trying to add 2 cell to a row.But that was effecting the other row's cell count.I changed my code to this and solved;
Table table = new Table();
table.background(new TextureRegionDrawable(new TextureRegion(new Texture("image/imgray.png"))));
table.add(missionTitle).width(width/1.5f).left();
table.add(new TextButton("!", skin)).height(height/23).width(width / 5).right();
table.row().fillX();
table.add(missionDesct).expandX();
table.add(goldAndExp).right();
table.row();
table.add(remainDay).left();
Screenshot
I'll be happy if someone fix my grammar problems.
Related
I have this piece of code
String [] titles = {"حذف", "شماره درس","گروه","واحد","نام","تعداد ثبت نامی","نام استاد","زمان امتحان","زمان کلاس","وضعیت پیشنیازی ها","محدودیت"};
String[][] value = new String[1][11];
JTable table = new JTable(value, titles);
table.setBounds(800,450,1100,80);
table.setBorder(BorderFactory.createLineBorder(Color.black, 2, true));
table.setRowHeight(40);
table.setForeground(Color.BLACK);
table.setBackground(Color.lightGray);
mainPanel.add(table);
but it doesn't work :/
It displays this while columns should have name :/
How can I fix this?
mainPanel.add(table);
The table header is only displayed automatically when you add the table to a scroll pane.
The code should be:
//mainPanel.add(table);
JScrollPane scrollPane = new JScrollPane( table );
mainPanel.add( scrollPane );
I'm trying to create a scrollpane that has a background. However, I want the background to take up more than the area of the scrollpane. For instance, Here is my background and colored in red is where I want the scrollpane to be:
However, when I add buttons I get the following result:
How can I limit the actual scrollpane part to just a section (colored in red in the above picture)?
Here is what I have so far. I toyed around with spacing/padding but that did not produce any good results:
Skin skin = Resources.getSkin(Resources.SKIN_JSON);
container = new Table();
container.setSize(Resources.VIRTUAL_WIDTH, Resources.VIRTUAL_HEIGHT);
this.addActor(container);
Table table = new Table();
// table.debug();
final ScrollPane scroll = new ScrollPane(table, skin);
table.pad(10).defaults().expandX().space(4);
table.setSize(Resources.VIRTUAL_WIDTH, Resources.VIRTUAL_HEIGHT);
container.add(scroll).expand().fill().colspan(1);
container.row().space(10).padBottom(10);
Image background = new Image(Resources.getAtlas(Resources.SKIN_ATLAS).findRegion("main-panel-horz"));
container.setBackground(background.getDrawable());
TextButton button1 = new TextButton("Button1", skin);
table.add(button1);
table.row();
TextButton button2 = new TextButton("button2", skin);
table.add(button2);
table.row();
TextButton button3 = new TextButton("button3", skin);
table.add(button3);
table.row();
TextButton button4 = new TextButton("button4", skin);
table.add(button4);
What you need to do is pad the outer table to get its contents to fit in the region of the background that you would like. (Or you could alternatively pad the cell that you put the scroll pane in.)
If you use a 9-patch drawable for the background, the padding of the outer table will be done for you automatically. You could also specify a TextureRegionDrawable in your skin Json and use that as the background. That would also allow you to pad the table automatically.
You can easily get texture region drawables from the skin with skin.getDrawable(drawableName);--no need to create an intermediate Image just to create a drawable out of a region.
Here's how you would create a TextureRegionDrawable with explicit padding in json:
com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable: {
main-panel-horz-padded: { region: main-panel-horz, leftWidth: 50, rightWidth: 50, topHeight: 50, bottomHeight: 50 }
},
Then in your code:
container.setBackground(skin.getDrawable("main-panel-horz-padded"));
I am trying to create a UI in JavaFX which should have two columns and one row. The row should span from top to bottom (100% height) and the columns should be 80% and 20% wide respectively. In the first column, I am creating a textarea, while the second one has a sidebar with multiple buttons.
The problem I am facing is that the textarea is not getting full height. I can change the height in px, but I want to change in percentage. I tried adding RowConstraint, but it does not works. Any idea how should I proceed?
public void start(Stage primaryStage)
{
primaryStage.setTitle("Particles");
primaryStage.setResizable(false);
GridPane grid = new GridPane();
grid.setVgap(10);
grid.setHgap(10);
RowConstraints row1 = new RowConstraints();
row1.setPercentHeight(100);
ColumnConstraints column1 = new ColumnConstraints();
column1.setPercentWidth(80);
ColumnConstraints column2 = new ColumnConstraints();
column2.setPercentWidth(20);
TextArea environment = new TextArea();
grid.add(environment, 0, 0);
Button start = new Button("START");
HBox hbBtn = new HBox(10);
hbBtn.setAlignment(Pos.CENTER);
hbBtn.getChildren().add(start);
grid.add(hbBtn, 1, 0);
Scene scene = new Scene(grid, 725, 500);
primaryStage.setScene(scene);
primaryStage.show();
}
My Output:
You need to add the Vgrow Priority of the TextField as Always
GridPane.setVgrow(environment, Priority.ALWAYS);
In your code :
TextArea environment = new TextArea();
grid.add(environment, 0, 0);
GridPane.setVgrow(environment, Priority.ALWAYS);
Output:
I want to add an item to the email column and to the remove column. How do you accomplish this?
I keep looking for a add method or something but I have no been able to find anything.
I have tried setData and redraw after setting some string but this did not work.
Here is the code I have so far:
Table emailTable = new Table(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
FormData fd_table = new FormData();
fd_table.bottom = new FormAttachment(emailText, -3);
fd_table.top = new FormAttachment(0, 10);
fd_table.right = new FormAttachment(emailLabel, 481);
fd_table.left = new FormAttachment(emailLabel, 0, SWT.LEFT);
Table emailTable.setLayoutData(fd_table);
Table emailTable.setHeaderVisible(true);
Table emailTable.setLinesVisible(true);
TableColumn emailColumn = new TableColumn(emailTable, SWT.NONE);
TableColumn emailColumn.setWidth(377);
TableColumn emailColumn.setText("Email");
TableColumn removeColumn = new TableColumn(emailTable, SWT.NONE);
TableColumn removeColumn.setWidth(100);
TableColumn removeColumn.setText("Remove");
You need to create TableItems with first argument in the constructor emailTable and set their text as described in http://www.vogella.com/tutorials/SWT/article.html#swt_table:
TableItem item = new TableItem(emailTable, SWT.NONE);
item.setText (0, "test#example.org");
I am using com.lowagie.text to create PDF in my code. All is working fine except I am trying to align my cell content vertically. I want cell text to be in the middle of the cell height.
This is my code
PdfPCell cell = new PdfPCell(new Phrase(value, fontValueNew));
cell.setBorder(o);
cell.setBackgroundColor(new Color(233,232,232));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
Here ,horizontal alignment is working fine but vertical alignment is not effective.
I'm not too sure as to why, but this works for me (vertical center alignment):
String headingLabel = "Test";
Paragraph heading = new Paragraph(headingLabel,
new Font(helvetica, 28, Font.NORMAL, new BaseColor(0, 0, 0)));
Float textWidth = ColumnText.getWidth(heading);
Float maxAllowed = 630f;
while (maxAllowed < textWidth) {
fontSize -= 2;
heading = new Paragraph(headingLabel,
new Font(helvetica, fontSize, Font.NORMAL, new BaseColor(0, 0, 0)));
textWidth = ColumnText.getWidth(heading);
}
heading.setAlignment(Element.ALIGN_CENTER);
PdfPCell titleCell = new PdfPCell();
titleCell.setHorizontalAlignment(Element.ALIGN_CENTER);
titleCell.setVerticalAlignment(Element.ALIGN_TOP);
titleCell.addElement(heading);
titleCell.setFixedHeight(65f);
headerTable.addCell(titleCell);
ALIGN_MIDDLE has integer value 5 defined in the the iText code. Please pay attention while you are writing ALIGN_MIDDLE a tip comes up "Possible value for vertical element." It means if your element is in vertical orientation then it will work as it calculates the center of the element. My suggestion is to replace ALIGN_MIDDLE with ALIGN_CENTER so your code will look like:
cell.setVerticalAlignment(Element.ALIGN_CENTER);
Try this:
PdfPCell cell = new PdfPCell(new Phrase(value, fontValueNew));
cell.setBorder(o);
cell.setBackgroundColor(new Color(233,232,232));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setVerticalAlignment(Element.ALIGN_CENTER);