Eexpand 2 more Titledpanes at once - swing

On these days i am refactoring java swing code to javafx.
And about some jpanels, i just refactored as JFXPanel and that JFXPanels` root is VBOX. the structure of JFXPanel is VBOX -> BorderPane -> TitledPane -> AnchorPane.
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="93.0" prefWidth="295.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BorderPane prefHeight="259.0" prefWidth="309.0">
<top>
<TitledPane animated="false" prefHeight="93.0" prefWidth="297.0" style="-fx-background-color: #eeeeee;" text="Compensation Options" textFill="#1b75bc">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="295.0" prefWidth="267.0">
<children>
<Button fx:id="mResetCountButton" layoutX="25.0" layoutY="5.0" mnemonicParsing="false" text="Reset Counts" textAlignment="CENTER" />
<Button fx:id="plotStatsButton" layoutX="123.0" layoutY="5.0" mnemonicParsing="false" text="Stats Panel" textAlignment="CENTER" />
<Button fx:id="gateStatsButton" layoutX="208.0" layoutY="5.0" mnemonicParsing="false" text="Gate State" textAlignment="CENTER" />
<Button fx:id="mLoadMatrixButton" layoutX="28.0" layoutY="37.0" mnemonicParsing="false" text="Load Matrix" textAlignment="CENTER" />
<Button fx:id="viewCompMatrix" layoutX="119.0" layoutY="37.0" mnemonicParsing="false" text="View Matrix" textAlignment="CENTER" />
<Label fx:id="mJCompMatrixCombo" layoutX="208.0" layoutY="41.0" text="Matrix Name" />
</children>
</AnchorPane>
</content>
</TitledPane>
</top>
</BorderPane>
</children>
</VBox>
And now i want to make JFXPanels as Accordion. When i searched in google i just saw some code which use and when i make Accordion tag, i just can use TitledPane below tag.
Is there any other way to make JFXPanels as Accordion reusing my code?...
And actually using Tag, i just can expand one titledPane at once.
How can i make JavaFX application with Accordion which can expand many titledPanes at once?
I just tried as make titledPanesclicklistener and resizing VBox which is wrapping titledPane and titledpanes size and some panes which in inside of titledpane.
such as
boolean titledPaneClicked = false;
TiteldPane.setOnAction((e)->{
if(titledPaneClicked){
TitledPane.setHeight(0);
Vbox.setHeight(0);
soemotherPanes.setHeight(0);
titledPaneClicked = !titledPaneClicked;
}else{
TitledPane.setHeight(previousSize);
Vbox.setHeight(previousSize);
soemotherPanes.setHeight(previousSize);
titledPaneClicked = !titledPaneClicked;
}
});
And it did not work. Plz help me :)

If your question is about how you can open close 2 TitledPanes at once, you can do so programmatically, for example by using a button :
Main.fxml (to make your code mcve always post the fxml name and imports)
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<VBox minWidth="-Infinity" prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="tests.xml.Controller">
<children>
<BorderPane>
<top>
<TitledPane fx:id="aTitledPane" animated="false" style="-fx-background-color: #eeeeee;" text="Compensation Options" textFill="#1b75bc">
<content>
<AnchorPane>
<children>
<Label text="Top pane expanded" />
</children>
</AnchorPane>
</content>
</TitledPane>
</top>
<center>
<TitledPane fx:id="bTitledPane" animated="false" style="-fx-background-color: #eeeeee;" text="Other Options" textFill="#1b75bc">
<content>
<AnchorPane>
<children>
<Label text="Bottom pane expanded" />
</children>
</AnchorPane>
</content>
</TitledPane>
</center>
<bottom>
<Button fx:id="openCloseButton" onAction="#openClose" text="Close" textAlignment="CENTER" />
</bottom>
</BorderPane>
</children>
</VBox>
And it controller:
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TitledPane;
public class Controller {
#FXML
private TitledPane aTitledPane, bTitledPane;
#FXML
private Button openCloseButton;
private final static String OPEN = "Open", CLOSE = "Close";
#FXML
void initialize(){
openCloseButton.setText(OPEN);
aTitledPane.setExpanded(false);
bTitledPane.setExpanded(false);
}
#FXML
private void openClose(){
System.out.println(openCloseButton.getText());
if(openCloseButton.getText().equals(OPEN)){
openCloseButton.setText(CLOSE);
aTitledPane.setExpanded(true);
bTitledPane.setExpanded(true);
}else{
openCloseButton.setText(OPEN);
aTitledPane.setExpanded(false);
bTitledPane.setExpanded(false);
}
}
}
Test it using :
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class FXMLTest extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("xml/Main.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(null);
}
}
If you want that opening / closing one TitledPane will open / close the other without using a button, remove the button from the fxml, and bind TitledPane.expandedProperty() of the two TitledPanes in the controller:
import javafx.fxml.FXML;
import javafx.scene.control.TitledPane;
public class Controller {
#FXML
private TitledPane aTitledPane, bTitledPane;
#FXML
void initialize(){
aTitledPane.expandedProperty().bindBidirectional(bTitledPane.expandedProperty());
}
}

I solved this problem just using VBox.
I made VBox, titledPane and VBox which contains some Btns, Labels, and so on.
VBox mainBox = new VBox();
TitledPane T1 = new TitledPane();
VBox content1 = new VBox();
T1.setContent(content1);
TitledPane T2 = new TitledPane();
VBox content2 = new VBox();
T2.setContent(content2);
mainBox.getChildren().addAll(T1, T2);
and then in MainVBox, titledPanes are shown like accordion.

Related

Adding java swing combobox to javafx application

I am trying to create a javafx application witch contanis just a tab pane and javafx combo box , this is my fxml witch i created by scene builder :
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="288.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TabPane layoutX="-2.0" prefHeight="400.0" prefWidth="288.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="tab1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<ComboBox layoutX="32.0" layoutY="39.0" prefHeight="26.0" prefWidth="86.0" />
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
and this is my simple Main just for call fxml
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* #author asus
*/
public class Main extends Application{
#Override
public void start(Stage primaryStage) throws Exception {
Scene scene= new Scene(FXMLLoader.load(getClass().getResource("/javaapplication3/test.fxml")));
primaryStage.setScene(scene);
primaryStage.setX(0);
primaryStage.show();
}
public static void main(String[] args) {
launch();
}
}
I am looking for a way to use swing combobox wich integerated with my fxml file and my application How can I do it , is there any way to use swing component in scene builder of fxml?

Error loading fxml javafx8

I am trying to load the following fxml file. I simply get an exception thrown pointing to line 19. I can load this in scenebuilder just fine, via Show preview in window menu item. At first I thought one couldn't have rectangles be children of a stackpane but that is the very example Oracle uses for javadoc and StackPane. Is there a known best practice to debug failures to load and fxml file? It flags the first child under reticlefilter stackpane.
The two children in question are the light blue rectangle with the yellow reticle.
<?xml version="1.0" encoding="UTF-8"?>
<?import org.cornova.javafx.*?>
<?import javafx.scene.shape.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<VBox fx:id="sliceRealEstate" alignment="TOP_CENTER" onMouseDragged="#onMouseDragged" onMousePressed="#onMousePressed" onScroll="#onScroll" onScrollStarted="#onScrollStarted" pickOnBounds="false" stylesheets="#org/cornova/javafx/xpssdr.css" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.cornova.xpssdr.controllers.SliceController">
<children>
<HBox fx:id="flagPole" pickOnBounds="false">
<children>
<Pane fx:id="flagPane" pickOnBounds="false" stylesheets="#org/cornova/javafx/xpssdr.css">
<children>
<StackPane fx:id="reticleFilter" alignment="BOTTOM_LEFT" pickOnBounds="false">
<children>
***<Rectangle fx:id="filter" fill="#3670ad" height="40.0" opacity="0.38" width="30.0" StackPane.alignment="CENTER" />***
<Rectangle fx:id="reticle" fill="#e8e82f" height="40.0" width="2.0" StackPane.alignment="CENTER" />
</children>
</StackPane>
<HBox fx:id="flag">
<children>
<VBox alignment="TOP_CENTER" spacing="10.0" style="-fx-background-color: black;" HBox.hgrow="NEVER">
<children>
<Button fx:id="close" mnemonicParsing="false" onAction="#close" text="cls">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="lock" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#lock" text="lck">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="record" layoutX="10.0" layoutY="29.0" mnemonicParsing="false" onAction="#record" text="rec">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="play" layoutX="10.0" layoutY="48.0" mnemonicParsing="false" onAction="#play" text="play">
<font>
<Font size="10.0" />
</font>
</Button>
</children>
</VBox>
<VBox alignment="CENTER" style="-fx-background-color: black;" HBox.hgrow="NEVER">
<children>
<HBox alignment="CENTER" VBox.vgrow="ALWAYS">
<children>
<VBox alignment="CENTER" HBox.hgrow="NEVER">
<children>
<HBox alignment="CENTER" VBox.vgrow="NEVER">
<children>
<VBox alignment="TOP_CENTER">
<children>
<ComboBox fx:id="rcvsrc" prefWidth="65.0" />
<ComboBox fx:id="txsrc" prefWidth="65.0" />
</children>
</VBox>
<Label fx:id="filterwidth" text="200" HBox.hgrow="NEVER" />
</children>
</HBox>
<HBox alignment="CENTER_LEFT" fillHeight="false" VBox.vgrow="NEVER">
<children>
<Label fx:id="nbon" text="nb" />
<Label fx:id="apfon" text="nr" />
<Label fx:id="nron" text="apf" />
<Label fx:id="qskon" text="qsk" />
</children>
</HBox>
</children>
</VBox>
<HBox HBox.hgrow="ALWAYS">
<children>
<Label fx:id="txindicator" alignment="CENTER" contentDisplay="CENTER" graphicTextGap="0.0" styleClass="largeindicators" text="TX" textAlignment="CENTER" textFill="RED">
<font>
<Font size="28.0" />
</font>
</Label>
<Label fx:id="sliceind" alignment="CENTER" contentDisplay="CENTER" styleClass="largeindicators" text="A" textAlignment="CENTER">
<font>
<Font size="27.0" />
</font>
</Label>
</children>
</HBox>
</children>
</HBox>
<VBox VBox.vgrow="NEVER">
<children>
<HBox alignment="CENTER" VBox.vgrow="NEVER">
<children>
<Label fx:id="signalLevel" alignment="CENTER" styleClass="mediumindicators" text="S9" HBox.hgrow="NEVER">
<opaqueInsets>
<Insets />
</opaqueInsets>
</Label>
<Label fx:id="signalplus" text="+20" />
<TextField fx:id="frequency" maxHeight="-Infinity" maxWidth="161.0" onAction="#onFrequencyChange" onMouseEntered="#scale" prefHeight="40.0" prefWidth="144.0" promptText="144.123456" styleClass="mediumindicators" />
</children>
</HBox>
</children>
</VBox>
<HBox VBox.vgrow="NEVER">
<children>
<ButtonBar buttonMinWidth="30.0" HBox.hgrow="NEVER">
<buttons>
<Button fx:id="spkr" mnemonicParsing="false" onAction="#displaySpkrSubmenu" text="spkr">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="dsp" mnemonicParsing="false" onAction="#displayDSPSubmenu" text="dsp">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="mode" layoutX="125.0" layoutY="17.0" mnemonicParsing="false" onAction="#displayModeSubmenu" text="rtty">
<font>
<Font size="10.0" />
</font>
</Button>
<Button layoutX="220.0" layoutY="17.0" mnemonicParsing="false" onAction="#displayXRITSubmenu" text="x/rit" fx:id="xrit">
<font>
<Font size="10.0" />
</font>
</Button>
<Button fx:id="dax" layoutX="315.0" layoutY="17.0" mnemonicParsing="false" onAction="#displayDAXSubmenu" text="dax">
<font>
<Font size="10.0" />
</font>
</Button>
</buttons>
<padding>
<Insets bottom="5.0" right="5.0" top="5.0" />
</padding>
</ButtonBar>
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
</children>
</Pane>
</children>
</HBox>
</children>
</VBox>
Additional information:
Exact text from exception
11:11:24.191 [nioEventLoopGroup-2-3] DEBUG org.cornova.xpssdr.views.SliceView - javafx.fxml.LoadException:
file:/home/walt/NetBeansProjects/XPSSDR/dist/run293699722/XPSSDR.jar!/SliceFlag.fxml:19
Code that does the load.
public VBox create() throws IOException {
VBox pane = null;
try {
pane = sliceLoader.load();
controller = sliceLoader.getController();
controller.setRadio(radio);
controller.setPan(pan);
controller = sliceLoader.getController();
controller.setPanadapter(pan);
controller.setParent(this);
controller.setSlice(slice);
wire();
Platform.runLater(() -> {
controller.wire();
});
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug(e.getLocalizedMessage());
log.debug(e.getMessage());
log.debug(e.toString());
}
}
return pane;
}
The error was actually in the constructor to the controller. Late last night I, in an attempt to get the reticle displayed, when it was a ResizableCanvas I decided to change it to Rectangle such that it would simply take a fill(). As this was an existing app and existing controller that worked, such as it was, I didn't create it from SceneBuilder's View sample controller and had inadvertantly not changed the #FXML in the constructor of the controller. In FXMLLoader.java I was eventually able to trace it to the point it was trying to invoke something, the controller. Oddly though, it was pointing at the wrong controller, which I did verify was correct in the fxml. A puzzlement but not the current one. To you comment James about there is always a stack trace. No, many times there is not. It just strikes me perhaps I am missing some best practice on debugging these (JavaFX fxml loader issues which I've had several of these last couple of days.

JavaFX - TabPane/Tab How to add content which fills the tab in size?

I am playing with JavaFX and i have a small problem, which i cannot solve.
I want to add a new Tab (from FXML) to a existing TabPane.
This is my code:
try
{
URL location = WPClientController.class.getResource("WPClient.fxml");
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(location);
fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
Node node = (Node) fxmlLoader.load(location.openStream());
Tab newTab = new Tab("engel", node);
fxTabWP.getTabs().add(newTab);
}
catch (Exception exception)
{
//no real error handling...just print the stacktrace...
exception.printStackTrace();
}
this code will result in:
The code works, but (as seen on the screenshot) the added node (a SplitPane here) uses it's preferred size (on TabPage, which is wrong for me).
The size of the added SplitPane should have the same size as it's parent container. (and it should grow and shrink, when the parent container grows or shrinks) (like BorderLayout in Swing)
EDIT (here is [now the correct] content of the TAB FXML):
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.test.ui.fx.client.ClientController">
<children>
<HBox prefHeight="100.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<children>
<SplitPane dividerPositions="0.29797979797979796" prefHeight="160.0" prefWidth="200.0" HBox.hgrow="ALWAYS">
<items>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<TreeView fx:id="fxTreeView" prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox fx:id="fxTreeNodeContentBox" prefHeight="100.0" prefWidth="200.0" />
</items>
</SplitPane>
</children>
</HBox>
</children>
</VBox>
My question: What is todo, so the SplitPane's size will dynamically fit it's parent container size?
Your FXML file has a root element with
<VBox maxHeight="-Infinity" maxWidth="-Infinity" ... >
The maxHeight and maxWidth attributes are preventing it from growing beyond its preferred size. (In addition, the preferred sizes of its child elements are, for some reason, set to fixed values.) If you remove these attributes it will allow the root element to grow as needed.

JavaFX start method everytime included tabcontent is called

How can I start a method every time a tab is called? I have a Main.fxml with a tabpane and two tabs, I've included a separate fxml for each tab (tab1.fxml, tab2.fxml).
Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="434.0" prefWidth="428.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.MainController">
<children>
<TabPane prefHeight="434.0" prefWidth="428.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab fx:id="tab1" text="Tab 1">
<content>
<fx:include source="tab1.fxml" />
</content>
</Tab>
<Tab fx:id="tab2" onSelectionChanged="#addView" text="Tab 2">
<content>
<fx:include source="tab2.fxml" />
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
MainController.java
public class MainController implements Initializable{
#FXML private Tab tab1;
#FXML private Tab tab2;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
}
#FXML public void addView(){
}
}
Each FXML has a Label which should show how often the tab(content) was called. So if I click on tab ("tab2") the counter label should show "1" and increment by +1 every time I call this tab again. This should happen by using a method within the tab controllers.
tab1.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="249.0" prefWidth="257.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.tab1Controller">
<children>
<Label fx:id="lbl_1" layoutX="92.0" layoutY="53.0" text="not clicked" />
</children>
</AnchorPane>
tab1Controller.java
public class tab1Controller implements Initializable{
#FXML public Label lbl_1;
private static int counter=0;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
}
public void addViewCounter(){
lbl_1.setText(""+counter);
counter++;
}
}
Tab2.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="249.0" prefWidth="257.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.tab2Controller">
<children>
<Label fx:id="lbl_2" layoutX="92.0" layoutY="53.0" text="not clicked" />
</children>
</AnchorPane>
tab2Controller.java
public class tab1Controller implements Initializable{
#FXML public Label lbl_2;
private static int counter=0;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
}
public void addViewCounter(){
lbl_2.setText(""+counter);
counter++;
}
}
I've already tried to solve this problem by using static methods and labels but i get NullPointerExceptions, seems like this doesn't work anymore with java 8.
Also I've tried to get the controller by using a FXMLloader ... this way I also get a NullPointerExceptions.
Isn't there an onCall method for the included fmxl or the anchorpane? Or maybe something that makes the controller initialize again.
Any other solutions or ideas?
Firstly, your counters should not be static. They belong to the controller instances, not the controller class.
You need three things:
A reference to the tabPane in the main controller
A reference to each of the tab controllers in the main controller.
A listener on the tabPane's selected tab, so that you can call a method when the selected tab changes
For the first, just do:
<TabPane fx:id="tabPane" prefHeight="434.0" ... >
in Main.fxml, and
#FXML private TabPane tabPane ;
in MainController.java.
For the second, you can use the "Nested Controller" technique.
You need to add an fx:id attribute to each of the fx:includes, and then just add references for the controllers in MainController.java. The rule is that if your fx:include has fx:id="x", then the controller from the corresponding FXML file can be injected into a variable with name xController. Here I have changed the class names for the controllers to Tab1Controller and Tab2Controller to follow the standard conventions (and avoid confusion).
In Main.fxml, change the fx:includes to include an fx:id:
<fx:include fx:id="tab1Content" source="tab1.fxml" />
<fx:include fx:id="tab2Content" source="tab2.fxml" />
In MainController.java:
#FXML private Tab1Controller tab1ContentController ;
#FXML private Tab2Controller tab2ContentController ;
Now in MainController's initialize() method just set up the listener:
public void initialize() {
tabPane.getSelectionModel().selectedItemProperty()
.addListener((obs, oldTab, newTab) -> {
if (newTab == tab1) {
tab1ContentController.addViewCounter();
} else if (newTab == tab2) {
tab2ContentController.addViewCounter();
}
});
}

autorun application in flex

I found an application that read the information about you webcam.
The thing is that when the application start you need to click on it to view your stats.
I have now connected the application to a button that animate the mx:list i created, But anyhow I need to fist click on the list to generate the output on a mx:label.
Any Ideas how I should do to just click on my show button to autorun camera stats.
Thanks
<?xml version="1.0"?>
<!-- behaviors\CompositeEffects.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
import mx.utils.ObjectUtil;
private var camera:Camera;
private function list_change(evt:ListEvent):void {
var tList:List = evt.currentTarget as List;
var cameraName:String = tList.selectedIndex.toString();
camera = Camera.getCamera(cameraName);
textArea.text = ObjectUtil.toString(camera);
}
]]>
</mx:Script>
<mx:Parallel id="ZoomRotateShow">
<mx:Zoom id="myZoomShow"
zoomHeightFrom="0.0"
zoomWidthFrom="0.0"
zoomHeightTo="1.0"
zoomWidthTo="1.0"
/>
<mx:Rotate id="myRotateShow"/>
</mx:Parallel>
<mx:Sequence id="ZoomRotateHide">
<mx:Rotate id="myRotateHide"/>
<mx:Zoom id="myZoomHide"
zoomHeightFrom="1.0"
zoomWidthFrom="1.0"
zoomHeightTo="0.0"
zoomWidthTo="0.0"
/>
</mx:Sequence>
<mx:List id="list"
dataProvider="{Camera.names}"
width="200"
change="list_change(event);"
hideEffect="{ZoomRotateHide}"
showEffect="{ZoomRotateShow}" visible="false"
/>
<mx:Label id="textArea" height="185" x="674" y="228" dataChange="{Camera.names}" />
<mx:Button id="myButton1"
label="Show!"
click="list.visible=true;"
/>
<mx:Button id="myButton2"
label="Hide!"
click="list.visible=false;"
/>
</mx:Application>
First, I split your function in two:
private function list_change(evt:ListEvent):void {
var tList:List = evt.currentTarget as List;
populateCameraInfo(tList.selectedIndex.toString());
}
private function populateCameraInfo(cameraName:String):void {
camera = Camera.getCamera(cameraName);
textArea.text = ObjectUtil.toString(camera);
}
Next (and I'm assuming you want the list to be visible to start with):
<mx:List id="list"
dataProvider="{Camera.names}"
width="200"
change="list_change(event);"
hideEffect="{ZoomRotateHide}"
showEffect="{ZoomRotateShow}"
selectedIndex="0"
creationComplete="populateCameraInfo('0')"
/>
So that way the first item is always selected.