put 2 radiobuttons in one column without overlapping JavaFX - javafx

I wanted to ask for help with one problem. I want to move two radio button in one column so that they will both take only as much space as textbox above them. How can I do this? Here is the code and screenshot of current improper version:
Please do not flag my question as duplicate if you are not 100% sure, ok? It is not nice to have your question flag as duplicate of other question, go to this other one and finds out that only common thing is that they are both about programming.
GridPane formGrid = new GridPane();
formGrid.setPadding(new Insets(5,5,5,5));
formGrid.setVgap(6);
formGrid.setHgap(4);
//first row
Label nameLabel = new Label("Name");
GridPane.setConstraints(nameLabel, 0, 0);
TextField nameInput = new TextField();
GridPane.setConstraints(nameInput, 1, 0);
Label ageLabel = new Label("Age");
GridPane.setConstraints(ageLabel, 2, 0);
TextField ageInput = new TextField();
GridPane.setConstraints(ageInput, 3, 0);
//secondRow
Label colourLabel = new Label("Colour");
GridPane.setConstraints(colourLabel, 0, 1);
TextField colourInput = new TextField();
GridPane.setConstraints(colourInput, 1, 1);
Label genderLabel = new Label("Gender");
GridPane.setConstraints(genderLabel, 2, 1);
ToggleGroup pickGender = new ToggleGroup();
RadioButton pickMale = new RadioButton("Male");
pickMale.setToggleGroup(pickGender);
pickMale.setSelected(true);
GridPane.setConstraints(pickMale, 3, 1, 1, 1);
RadioButton pickFemale = new RadioButton("Female");
pickFemale.setToggleGroup(pickGender);
GridPane.setConstraints(pickFemale, 4, 1, 1, 1);
//third row
Label typeLabel = new Label("Type");
GridPane.setConstraints(typeLabel, 0, 2);
//combobox
ComboBox<String> typeBox = new ComboBox<>();
GridPane.setConstraints(typeBox, 1, 2);
Label breedLabel = new Label("Breed");
GridPane.setConstraints(breedLabel, 2, 2);
TextField breedInput = new TextField();
GridPane.setConstraints(breedInput, 3, 2);
//fourth row
Label categoryLabel = new Label("Category: ");
GridPane.setConstraints(categoryLabel, 0, 3);
ToggleGroup pickCategory = new ToggleGroup();
RadioButton pickLost = new RadioButton("Lost");
pickLost.setToggleGroup(pickCategory);
pickLost.setSelected(true);
GridPane.setConstraints(pickLost, 1, 3);
RadioButton pickFound = new RadioButton("Found");
pickLost.setToggleGroup(pickCategory);
GridPane.setConstraints(pickFound, 2, 3);
RadioButton pickAdoption = new RadioButton("Adoption");
pickLost.setToggleGroup(pickCategory);
GridPane.setConstraints(pickAdoption, 3, 3);
//fifth row
Label descriptionLabel = new Label("Description");
GridPane.setConstraints(descriptionLabel, 0, 4);
TextArea descriptionInput = new TextArea();
GridPane.setConstraints(descriptionInput, 1, 4, 2, 1);
formGrid.getChildren().addAll(nameLabel, nameInput, ageLabel, ageInput);
formGrid.getChildren().addAll(colourLabel, colourInput, genderLabel, pickMale, pickFemale);
formGrid.getChildren().addAll(typeLabel, typeBox, breedLabel, breedInput, categoryLabel);
formGrid.getChildren().addAll(pickLost, pickFound, pickAdoption, descriptionLabel, descriptionInput);

Think of it the other way around. The "Female" radio button is in column 4, and so it is to the right of anything in column 3. Column 3 is being forced to be wide enough to hold the two text fields, which is what is forcing that radio button so far to the right. If you want the text fields to span the same horizontal space as the two radio buttons, let them use both the columns the radio buttons occupy: i.e. let the text fields span columns 3 and 4.
TextField ageInput = new TextField();
GridPane.setConstraints(ageInput, 3, 0, 2, 1);
TextField breedInput = new TextField();
GridPane.setConstraints(breedInput, 3, 2, 2, 1);
Now columns 3 and 4 contain those two text fields, column 3 contains the "Male" radio button, and column 4 contains the "Female" radio button.
I'm not sure if everything you posted is the whole form, but you might also want to increase the column span of the text area to make it work nicely:
GridPane.setConstraints(descriptionInput, 1, 4, 4, 1);
With those changes I get
(If it's important to you, you can avoid the "Female" check box from being pushed to the right by also setting the column span of the "Adoption" check box to 2.)
Another option is (starting with your original code) to wrap the two radio buttons in a HBox, and place the HBox in the grid pane instead of the radio buttons:
RadioButton pickMale = new RadioButton("Male");
pickMale.setToggleGroup(pickGender);
pickMale.setSelected(true);
RadioButton pickFemale = new RadioButton("Female");
pickFemale.setToggleGroup(pickGender);
HBox genderButtons = new HBox(4, pickMale, pickFemale);
GridPane.setConstraints(genderButtons, 3, 1);
// ...
formGrid.getChildren().addAll(colourLabel, colourInput, genderLabel, genderButtons);
However, I prefer the previous approach. (Your mileage may vary.)

Related

QTableWidget set column and get column

I'm trying to set programmatically some values of my QTableWidget, but it seems not working.
In my primary thread, I set the table with (PRIMARY_SET):
Status="N";
Number = QString::number(x);
Name= "abc;
nrow=i;
QTableWidgetItem *item_Number = new QTableWidgetItem(Number);
QTableWidgetItem *item_Name = new QTableWidgetItem(Name);
QTableWidgetItem *item_Status = new QTableWidgetItem(Status);
QTableWidgetItem *icon_item = new QTableWidgetItem;
QIcon icon("path/to/.png");
icon_item->setIcon(icon);
ui->TabKeyAlarm_TableED->setItem(nrow, 0, item_Number);
ui->TabKeyAlarm_TableED->repaint();
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
ui->TabKeyAlarm_TableED->setItem(nrow, 1, icon_item);
ui->TabKeyAlarm_TableED->repaint();
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
ui->TabKeyAlarm_TableED->setItem(nrow, 2, item_Name);
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
ui->TabKeyAlarm_TableED->setItem(nrow, 3, item_Status);
ui->TabKeyAlarm_TableED->repaint();
ui->TabKeyAlarm->repaint();
ui->centralWidget->repaint();
for n row and it works.
What I have to do after that is to change the icon and the "Status" on particular row if an event happens.
This is my controll in a separated thread, which do not works (CHECK):
QTableWidgetItem *_getItem = ui->TabKeyAlarm_TableED->item(n_MOD,3);
if (_getItem)
if (_getItem->text() != "K")
{
QEvent(QEvent::Type(QEvent::User+5)));
}
It continuosly call the User+5 event. How can I check if _getItem in row n_MOD and column 3 has already "K" text set ? The result is always _getItem->text() "no such value"...
Then, this is the code for User+5 event (SECOND_SET):
QString _Status_check="";
Status="K";
QTableWidgetItem *icon_item = new QTableWidgetItem;
QTableWidgetItem *item_Status = new QTableWidgetItem(Status);
while (_Status_check != "K")
{
QIcon icon("path/to/.png");
icon_item->setIcon(icon);
ui->TabKeyAlarm_TableED->setItem(n_MOD, 1, icon_item);
ui->TabKeyAlarm_TableED->setItem(n_MOD, 3, item_Status);
_Status_check = ui->TabKeyAlarm_TableED->item(n_MOD,3)->text();
I have to use that "while", because otherwise most of the times _Status_check confirm me that the text in row n_MOD column 3 has still the old text...
So my questions are :
1) In CHECK section, how can I check if the element has already the value "K" ?
2) In SECOND_SET section, why it seems that it takes more than one attempt to set the value in row,column?

Changes from 3.5 to 4.0

I need to help to port my 3.5 rc.lua to 4.0. I try to set one progressbar.
It used to be :
mybacklight = awful.widget.progressbar()
mybacklight:set_width(12)
mybacklight:set_height(10)
mybacklight:set_vertical(true)
mybacklight:set_background_color("#131211")
mybacklight:set_border_color(nil)
The new version should be :
mybacklight = wibox.widget.progressbar {
max_value = 1,
value = brightness_new,
forced_width = 12,
forced_height = 10,
background_color = "#131211",
border_color = nil,
color = {type="linear", from = {0, 0}, to = {0, 20},
stops = { {0, "#F6F6F6"}, {0.5,
"#bdbdbd"}, {1.0, "#3b3b3b"} } },
widget = wibox.widget.progressbar,
direction = 'east',
layout = wibox.container.rotate
}
The 3.5 version works (no errors) but does no more give the expected result, it should be a vertical progressbar, it is, but the progression itself is horizontal.
The 4.0 version makes no error, except that it takes all the place with red (default ?) colors.
First of all, the imperative syntax isn't gone, you can still do it "the old way". It is fully supported and the declarative one is "compiled to" the old one.
Now, to answer the question, the code should look like (untested):
mybacklight = wibox.widget {
{
max_value = 1,
value = brightness_new,
background_color = "#131211",
color = {type="linear", from = {0, 0}, to = {0, 20},
stops = { {0, "#F6F6F6"}, {0.5,
"#bdbdbd"}, {1.0, "#3b3b3b"} }
},
widget = wibox.widget.progressbar,
},
forced_width = 12,
forced_height = 10,
direction = 'east',
layout = wibox.container.rotate
}
Changes:
The composite widget constructor is wibox.widget. You used the progressbar constructor to contruct a rotate container
Indentation to make the code more readable
You had 2 widget in the same block, this isn't supported.
Reference https://awesomewm.org/apidoc/classes/wibox.widget.progressbar.html#

Align Image inside cell to the right doesn't work

I need to align on the headers an image to the right. This is my code:
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("8cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("4cm");
column.Format.Alignment = ParagraphAlignment.Right;
eRow.Cells[0].AddParagraph("Some text");
eRow.Cells[1].AddParagraph("Some text");
eRow.Cells[2].Format.Alignment = ParagraphAlignment.Right;
image = eRow.Cells[2].Elements.AddImage(imagePath);
image.LockAspectRatio = false;
image.Width = Unit.FromInch(0.16);
image.Height = Unit.FromInch(0.09);
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
But it's always to the left, any help please?
I know it is a bit late
But you have to wrap your image in a paragraph.
http://forum.pdfsharp.net/viewtopic.php?f=2&t=158
Something like (I use parts of your code)
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
//I assume eRow is just a row added to your table
var eRow = table.AddRow();
var paragraph = eRow.Cells[0].AddParagraph();
//set the alignment on the paragraph object
paragraph.Format.Alignment = ParagraphAlignment.Right;
paragraph.AddImage(imagePath);
I had the same problem at it worked with the code/link from above.
The lines
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
logically take the image out of the cell. This creates an image that can appear anywhere on the page, not just inside the cell.
Maybe it works if you simply remove those five lines. Maybe it works if you add a Paragraph to the Cell and add the Image to the cell.
If you would have supplied an MCVE I would have tried if my suggestions work. But you only show a code snippet.
The line image.LockAspectRatio = false; is superfluous, but does no harm.
It will work if you do like that:
row.Cells[1].AddParagraph().AddImage(fileName);
row.Cells[1].Format.Alignment = ParagraphAlignment.Right;

how to place two tables horizontally within a pdf file?

I have created two tables on pdf file. Now I wants to arrange them in horizontal position. That is table 1 should be at left of page, and table 2 should be at the exact right position of table 1. But when Iam doing, table 1 comes correctly, but table2 is not exact horizontal with table1.table 2 is just placed as left aligned. How can I place this table 2 as horizontally parallel with table1?
var doc1 = new Document(PageSize.A4);
PdfWriter.GetInstance(doc1, new FileStream(path + "/" + pdf_name + "", FileMode.Create));
doc1.Open();
var table1 = new PdfPTable(1); //table1
table1.HorizontalAlignment = Element.ALIGN_LEFT;
table1.SpacingBefore = 50;
table1.DefaultCell.Border = 1;
table1.WidthPercentage = 40;
PdfPCell cell = new PdfPCell(new Phrase(student_name, boldTableFont));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
table1.AddCell(cell);
doc1.Add(table1);
var table2= new PdfPTable(1); //table2
table2.DefaultCell.Border = 1;
table2.HorizontalAlignment = 2;
table2.SpacingBefore = 50;
table2.WidthPercentage = 40;
PdfPCell cell21 = new PdfPCell(new Phrase("success", body));
cell21.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table2.AddCell(cell21);
doc1.Add(table2);
doc1.Close();
Create a new table with a single row and two columns.
Place first table in the first row first column and second table in the first row second column
Give the alignment of the first column as left , and for the other right
hope this helps..

Issue with JuiceUI slider control after postback

I am using the DynamicControlsPlaceholder by Denis Bauer to save the viewstate of dynamic controls after postback.
I used DynamicControlsPlaceholder before in an earlier part of my project and it worked flawlessly.
However, today I have run into difficulty. I have created a page where there are a number of text labels, slider bars and textboxes (defined by how many elements there are on a database) as shown below. The slider bars are JuiceUI slider controls and the text boxes are normal ASP.NET textboxes.
After postback the text labels (literal controls) and pie chart disappear, the textboxes reduce in size (text inside remains) and the sliderbars are reset to the lowest value without the ability to move the slider (the sliders cannot move at all).
I am quite new to ASP.NET and I am completely stumped as to why this is happening. Do you think it is a problem with the dynamic control placeholder, JuiceUI slider or my code (see below)?
{
SqlCeCommand cmdb = new SqlCeCommand();
cmdb.CommandText = "SELECT CriteriaName,CriteriaDesc FROM tblCriteria WHERE (DecisionID = #DID)";
cmdb.Parameters.AddWithValue("#DID", DID.Text.Trim());
cmdb.Connection = sqlConnection1;
reader = cmdb.ExecuteReader();
string[] criterianames = new string[critno];
string[] criteriadescs = new string[critno];
int i = 0;
while (reader.Read())
{
criterianames[i] = reader["CriteriaName"].ToString().Trim();
criteriadescs[i] = reader["CriteriaDesc"].ToString().Trim();
i++;
}
reader.Close();
Cont2.Controls.Add(new LiteralControl("<h3>Thank you for contributing to the following decision.<h4>Decision Goal: " + dgoal + "</h4><br><br><center>"));
Series weights = new Series();
weights.ChartType = SeriesChartType.Pie;
double[] yBar = new double[critno];
string[] xBar = new string[critno];
xBar = criterianames;
for (i = 0; i < critno; i++)
{
yBar[i] = 1;
}
ChartArea ca = new ChartArea();
ca.Position = new ElementPosition(0, 0, 100, 100);
ca.InnerPlotPosition = new ElementPosition(0, 0, 100, 100);
ca.BackColor = System.Drawing.Color.Transparent;
Chart piechart = new Chart();
piechart.RenderType = RenderType.ImageTag;
piechart.ChartAreas.Add(ca);
piechart.BackColor = System.Drawing.Color.Transparent;
piechart.Palette= ChartColorPalette.BrightPastel;
piechart.BorderColor = System.Drawing.Color.Black;
piechart.BorderSkin.PageColor = System.Drawing.Color.Transparent;
piechart.BorderSkin.BackColor = System.Drawing.Color.Transparent;
piechart.Width = 800;
piechart.Series.Add(weights);
piechart.ImageStorageMode = ImageStorageMode.UseImageLocation;
piechart.ImageLocation = "~/TempImages/ChartPic_#SEQ(300,3)";
piechart.Series[0].Points.DataBindXY(xBar, yBar);
piechart.DataBind();
Cont2.Controls.Add(piechart);
Cont2.Controls.Add(new LiteralControl("</center><h3>Please provide a weighting for each criterion.</h3><p>Please provide a weighting for each criterion along with a description of why you made this choice. </p>"));
for (i = 0; i < critno; i++)
{
Cont3.Controls.Add(new LiteralControl("<h3>" + criterianames[i] + "</h3><p><strong>Description: </strong>" + criteriadescs[i] + "</p><center>"));
Juice.Slider weightslider = new Juice.Slider();
weightslider.ID = "w" + i.ToString();
weightslider.Min = 1;
weightslider.Value = 50;
weightslider.Max = 100;
weightslider.AutoPostBack = true;
Cont3.Controls.Add(weightslider);
weightslider.ValueChanged += (o, a) =>
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + weightslider.Value.ToString() + "');", true);
};
TextBox wdesc = new TextBox();
wdesc.ID = "wd" + Convert.ToString(i);
wdesc.Rows = 3;
wdesc.Width = 900;
wdesc.TextMode = TextBoxMode.MultiLine;
Cont3.Controls.Add(wdesc);
Cont3.Controls.Add(new LiteralControl("</center>"));
}
Cont3.Controls.Add(new LiteralControl("<p align='right'>"));
Button continue1 = new Button();
continue1.Text = "Continue";
Cont3.Controls.Add(continue1);
Cont3.Controls.Add(new LiteralControl("</p>"));
// Database Disconnect
sqlConnection1.Close();
}
Many thanks for any help you can provide,
Kind regards,
Richard
You could eliminate or confirm the problem exists with Juice UI by creating a page containing nothing more than a Juice UI slider, one of these dynamic placeholders and a label. That'd be the first stop.
If you do run into problems with Juice UI, you can use it's cousin Brew

Resources