I need to know whether it is possible to add values to a ComboBox at different times.
ObservableList<String> options1
= FXCollections.observableArrayList(
"Civil (CE)", "Computer (CT)", "Electrical (EEE)", "Electronics (ELS)",
"Mechanical (ME)");
comboBox1 = new ComboBox(options1);
comboBox1.setPrefSize(280, 30);
This is my code of ComboBox. In it I added 5 values at a time. But is it possible to add each value at different times, for example, add values one by one in a while loop. I tried it and the result was that each value overlapped previously added values, and as a result only one value was present in the ComboBox at the end. This the code with while loop -
while (rs.next()) {
subject = rs.getString("subname");
ObservableList<String> options1 = FXCollections.observableArrayList(subject);
comboBox1 = new ComboBox(options1);
}
Can I add values to ComboBox at different times, one after another, without overlapping the previous value ?
Yes, you can add/remove items at any moment using getItems()
comboBox1.getItems().add("Beer");
comboBox1.getItems().add("Whiskey");
comboBox1.getItems().add("Water");
or directly updating list:
options1.add("Milk");
Related
I have a collection with 50 objects.
Each object contains several things but we have at least
OrgNr, Register_Id, Name, MailDate, Subject
for each object.
Assume these have the following values
OrgNr = "2556745-8145"
Register_Id = "1001"
Name = "Thailaan Asian Market"
MailDate = "2016-05-23 13:01:20"
Subject = "LPP failure"
So when I read the first object and want to add the above five fields to the ListBox I want it to be displayed like this and as one column.
2556745-8145/1001
Thailaan Asian Market
2016-05-23 13:01:20
LPP failure
So all these five fields is like one item and should be clickable.
I have been looing everywhere but the only example I have found is this
http://www.codeproject.com/articles/2695/an-editable-multi-line-listbox-for-net.
I can't use this example because I want to be able to control when I want to add CR LF which is after each written field value
//Tony
I have a requirement in which I have an af:query panel which after querying populates an af:table.
Now based on the table rows when any 1 row is selected, the graphs below it should be populated based on some columns.
Now my problem is that on search when the table is populated for the first time, no row is selected.
I need the first row to be selected automatically. I have searched multiple solutions from the net forums but till now haven't found any working solution.
Please help me what code should I use to select a row programmatically. and also where should I put this code in the backing bean.
As you've correctly mentioned, at the first render of the table no row is selected. I've encountered this problem too, and i've dealt with it by calling a getting the first row of the corresponding VO on BeforePhase (i.e: on the page first rendering or refresh).
I understand that you intend to do so for the first searching.
The af:query component has a property called QueryListener. You can link it with a method inside a backing bean. The content should be like:
private QueryEvent qEvent = null;
public void queryListener(QueryEvent queryEvent) {
setQEvent(queryEvent);
JSFUtils.invokeMethodExpression("#{bindings.YourViewObjectNameViewCriteriaQuery.processQuery}", Object.class,
QueryEvent.class, getQEvent());
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry(); //Edited
DCBindingContainer bc = (DCBindingContainer)bindings;
DCIteratorBinding iterator = bc.findIteratorBinding("YourViewObject1Iterator");
Row r = iterator.getCurrentRow(); //Here you've got the very first row, and can operate with it
.....
}
public void setQEvent(QueryEvent qEvent) {
this.qEvent = qEvent;
}
public QueryEvent getQEvent() {
return qEvent;
}
With this, you should be able to get the first row when the query is executed (i.e: when the search is done).
After getting the first row, you can programmatically the graph process execution or whatever you do.
NOTE: invokeMethodExpression can be found inside JSFUtils, which is a starndard class with static methods which source code you can download here: JSFUtils.java
//MyGrid
ListStore< PojoSurveyReportApproved> store = new ListStore< PojoSurveyReportApproved>(loader);
List<ColumnConfig> configs = getSurvey(list);
cm = new ColumnModel(configs);
cp = new ContentPanel();
final Grid< PojoSurveyReportApproved> grid = new Grid< PojoSurveyReportApproved>(store, cm);
grid.setTitle("ddddddd");
grid.setBorders(true);
grid.getAriaSupport().setDescribedBy(toolBar.getId() + "-display");
cp.removeAll();
cp.add(grid);
This is my Grid, which loads dynamically. whenever it changes, all the records from the grid should be retrieved, where i can easily export it to Excel.
Just i want is all the records in the grid eighter as an array or list, is there any listener to handle it or any way i can get all the records.
I have tried out in some ways by adding a listener to a store by it does not gives me result
Did you try-
store.getAll(); ?
This code takes all the records in the grid and returns as a collection. However, you may need to take another arrayList to use the store values depending on your needs.
I'm using a parent to pass a multi-dimensional array to a child. Structure of the array, named projectPositions is as follows (with example data):
projectPositions[0][0] = 1;
projectPositions[0][1] = 5;
projectPositions[0][2] = '1AD';
projectPositions[0][3] = 'User name';
I need to take this inherited array and turn it into an arrayCollection so that I can use it as a dataProvider. Currently, my init function (which runs onCreationComplete) has this code in it to handle this task of array -> arrayCollection:
for (var i:int = 0; i < projectPositions.length; i++)
{
tempObject = new Object;
tempObject.startOffset = projectPositions[i][0];
tempObject.numDays = projectPositions[i][1];
tempObject.role = projectPositions[i][2];
tempObject.student = projectPositions[i][3];
positionsAC.addItemAt(tempObject, positionsAC.length);
}
Then, during a repeater, I use positionsAC as the dataprovider and reference the items in the following way:
<mx:Repeater id="indPositions" dataProvider="{positionsAC}" startingIndex="0" count="{projectPositions.length}">
<components:block id="thisBlock" offSet="{indPositions.currentItem.startOffset}" numDays="{indPositions.currentItem.numDays}" position="{indPositions.currentItem.role}" sName="{indPositions.currentItem.student}" />
</mx:Repeater>
This all works fine and returns the desired effect, but the load time of this application is around 10 seconds. I'm 99% sure that the load time is caused by the array -> arrayCollection for loop. Is there an easier way to achieve the desired effect without having to wait so long for the page to load?
The issue your having loading items could be because you are using a repeater instead of a list class.
With a repeater, there will be a block created in memory, and drawn on the screen. So, if you have 100 items in your array, then 100 blocks will be created. this could slow down both initial creation and the overall app.
A list based class focuses on a technique called renderer recycling; which means only the displayed elements are created and rendered on the screen. So, depending on settings, you'd usually have 7-10 'block' instances on the screen, no matter how many items you have in your array.
change
positionsAC.addItemAt(tempObject, positionsAC.length);
to
positionsAC.addItem(tempObject);
addItemAt is causing a reindex of the collection which can greatly slow down the collection.
[EDIT]
Put this trace statement before and after the loop
take the output and subtract one from the other and that will show how many milliseconds the loop has run.
var date:Date = new Date( );
trace( date.getTime())
I am working on a charting control where I am plotting the "analysis range," which is just two vertical lines on the chart. A problem arises when I want to change the analysis range, because I don't know how to remove only the two analysis range lines, so I end up clearing the chart and plotting the actual data values and whatnot again. Is there a way to tag these UI elements (i.e. analysis range is a gridline UI element) so that I can remove them specifically? I suppose I could save the "index" of the UI element somewhere and delete these, but I am wondering if there is a cleaner way of doing this. Thanks a lot.
All UIElements have a UID which is a string. You could set the UID of the range lines to something predictable. Keep in Mind that UID must be unique. Then when you need to remove only the gridlines, you iterate through the Children collection gathering a list of the UI elements that need to be removed, then remove them.
Something like this:
Canvas c = new Canvas();
c.Children.Add( new UIElement() { Uid = "Line1" } );
c.Children.Add( new UIElement() { Uid = "Line2" } );
c.Children.Add( new UIElement() { Uid = "Line3" } );
c.Children.Add( new UIElement() { Uid = "Text1" } ); //This is added as a sample
List<UIElement> itemstoremove = new List<UIElement>();
foreach (UIElement ui in c.Children)
{
if (ui.Uid.StartsWith("Line"))
{
itemstoremove.Add(ui);
}
}
foreach (UIElement ui in itemstoremove)
{
c.Children.Remove(ui);
}
That should work. A quick test of this code in debug shows the Children count at 1, with only the UIElement with Uid of Text1 present in the list.
When you add the two lines to the Canvas, can't you hold a reference to the two lines. That way, when you need to redraw them, just do a Canvas.Children.Remove(line1) and Canvas.Children.Remove(line2). Then update your references for the lines and re-add them to the Canvas. You could even just update the X and Y values of the lines themselves rather than removing and re-adding them. This way, the Chart would just move the lines.
But, basically the key is to maintain a reference to the lines after adding them to the Canvas.