Fit textfield width when column is resized - dynamic

I have a treeTableView and in its header I have a Label and Textbox. I want the width of textbox to increase also when the column is increased by resizing of it.
How to do that?
How to get dynamic column width? Or how to set dynamic width to textbox as per column?
Code:
<TableView fx:id="tableView" layoutX="1.0" layoutY="1.0"
minHeight="580.0" prefWidth="434.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS">
<columns>
<TableColumn style="-fx-font-family: Calibri; -fx-font-size: 11px;" text="MessageId">
<cellValueFactory>
<PropertyValueFactory property="messageId" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="110.0" style="-fx-font-family: Calibri; -fx-font-size: 11px;" text="Digest Reference">
<cellValueFactory>
<PropertyValueFactory property="digestReference" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="115.0" style="-fx-font-family: Calibri; -fx-font-size: 11px;" text="Message Reference">
<cellValueFactory>
<PropertyValueFactory property="messageRef" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="115.0" style="-fx-font-family: Calibri; -fx-font-size: 11px;" text="Deal Number">
<cellValueFactory>
<PropertyValueFactory property="dealNo" />
</cellValueFactory>
</TableColumn>
<TableColumn style="-fx-font-family: Calibri; -fx-font-size: 11px;" text="Digest Value">
<cellValueFactory>
<PropertyValueFactory property="digestValue" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="100.0" style="-fx-font-family: Calibri; -fx-font-size: 11px;" text="Updated Date Time">
<cellValueFactory>
<PropertyValueFactory property="updateTime" />
</cellValueFactory>
</TableColumn>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
JAVA Code:
for (TableColumn<NonRepudiation, ?> tableColumn : tableView.getColumns()) {
double width = tableColumn.getWidth();
VBox vBox = new VBox();
vBox.autosize();
vBox.setPrefWidth(tableColumn.getMaxWidth());
double width = tableColumn.getWidth();
VBox vBox = new VBox();
vBox.autosize();
vBox.setPrefWidth(tableColumn.getMaxWidth());
HBox lableBox = new HBox();
lableBox.setPrefWidth(width);
lableBox.getStyleClass().add("labelBoxTxt");
StackPane HL = new StackPane();
HL.getStyleClass().add("greyBorder");
Label label = new Label(tableColumn.getText());
label.setPrefWidth(width);
label.alignmentProperty().setValue(Pos.TOP_LEFT);
TextField textField = new TextField();
textField.setPrefWidth(width);
textField.textProperty().addListener(filterTable(tableColumn));
HBox textInputBox = new HBox();
textInputBox.getChildren().add(textField);
lableBox.getChildren().add(label);
HBox.setMargin(textField, new Insets(3,3,3,0));
vBox.getChildren().addAll(lableBox, HL, textInputBox);
tableColumn.setGraphic(vBox);
}

Basically you need to use HBox.setHgrow() method. Here refactored code of yours:
for ( TableColumn tableColumn : tableView.getColumns() ) {
// build label
Label label = new Label( tableColumn.getText() );
HBox lableBox = new HBox( label );
lableBox.getStyleClass().add( "labelBoxTxt" );
lableBox.setAlignment( Pos.CENTER );
// build hor line
StackPane HL = new StackPane();
HL.getStyleClass().add( "greyBorder" );
// build text field
TextField textField = new TextField();
HBox.setHgrow( textField, Priority.ALWAYS );
HBox.setMargin( textField, new Insets( 3 ) );
HBox textInputBox = new HBox( textField );
// put together
VBox vBox = new VBox( lableBox, HL, textInputBox );
tableColumn.setText( "" );
tableColumn.setGraphic( vBox );
}

I found the solution.
Set a css class to your talbe view.
<TableView styleClass="k-table-view"
Then add css class to vbox
vBox.getStyleClass().add("k-column-graphic");
Add css rule
.k-table-view .column-header > .label {
-fx-content-display: graphic-only;
}
.k-column-graphic {
-fx-alignment: center-left;
}
I am having dynamic width for the graphic.

Related

Positioning actionbar items on android

I have this code
<template>
<Page>
<ActionBar title="Action Items">
<StackLayout orientation="horizontal">
<Image src="res://icon" width="40" height="40"
verticalAlignment="center" />
<Label text="NativeScript" fontSize="24"
verticalAlignment="center" />
</StackLayout>
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back"
(tap)="onNavBtnTap()">
</NavigationButton>
<ActionItem (tap)="onShare()" ios.systemIcon="9"
ios.position="left" android.systemIcon="ic_menu_share"
android.position="actionBar">
</ActionItem>
<ActionItem (tap)="onDelete()" ios.systemIcon="16"
ios.position="right" text="delete" android.position="popup">
</ActionItem>
</ActionBar>
<ScrollView>
<StackLayout class="home-panel">
<!--Add your page content here-->
<Label textWrap="true" text="Play with NativeScript!"
class="h2 description-label">
{{first}}
</Label>
<Label textWrap="true"
text=" Write code in the editor or drag and drop components to build a NativeScript mobile application."
class="h2 description-label" />
<Label textWrap="true"
text="Scan the QR code with your mobile device and watch the changes sync live while you play with the code."
class="h2 description-label" />
</StackLayout>
</ScrollView>
</Page>
</template>
<script>
export default {
data() {
return {
first: "Once"
};
}
};
</script>
<style scoped>
.home-panel {
vertical-align: center;
font-size: 20;
margin: 15;
}
.description-label {
margin-bottom: 15;
}
</style>
which produces
My question is how come the back button aligned itself left and the others right without explicitly coding left or right?
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back"
(tap)="onNavBtnTap()">
</NavigationButton>
and the other buttons are aligning to the right
<ActionItem (tap)="onShare()" ios.systemIcon="9"
ios.position="left" android.systemIcon="ic_menu_share"
android.position="actionBar">
</ActionItem>
<ActionItem (tap)="onDelete()" ios.systemIcon="16"
ios.position="right" text="delete" android.position="popup">
</ActionItem>
<NavigationButton/> is by default on the left, as it's just calls into the native setNavigationIcon api:
https://developer.android.com/reference/android/widget/Toolbar#setNavigationIcon(android.graphics.drawable.Drawable)
While the other <ActionItem> elements are added with the Menu api:
https://developer.android.com/reference/android/widget/Toolbar#getMenu()
For your other question, you can do the following:
<Label :text="`${first} Play with NativeScript!`" textWrap="true" class="h2 description-label" />
:text makes it a binding, the then you pass in a regular JavaScript string literal.
An alternative would be:
:text="first + ' Play with NativeScript!'"
Both ways should work fine.

How to set the checkbox label width in the xul file?

I am developping an zotero plugin, and would like to draw a dialog. The width of dialog, groupbox, hbox, checkbox etc have been tried, minwidth, maxwidth have also been tried, but it doesn't work. I would like to get a line break at proper position of the labels.
Many thanks!
code:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://zotero-platform/content/preferences.css"?>
<!DOCTYPE window SYSTEM "chrome://zoteroupdateifs/locale/options.dtd">
<!--给作者加粗加星-->
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
id="updateifs-test"
title="&author-process-win;"
width="200"
height="300"
style="padding: 10px;"
buttons="accept,cancel"
ondialogaccept=" window.close();"
ondialogcancel="window.close();">
<stringbundleset id="stringbundleset">
<stringbundle id="updateifs-options" src="chrome://zotero-updateifs/locale/options.properties"/>
</stringbundleset>
<groupbox width="200">
<caption label="&update-abbr;"/>
<separator class='thin'/>
<description style="width: 220px">&update-journal-abbr;</description>
<separator class='thin'/>
<hbox style="margin: 0" width="200">
<checkbox id="id-updateifs-add-update" label="&add-update;" />
</hbox>
<separator class='thin'/>
<hbox style="margin: 0" maxwidth="200">
<checkbox id="id-updateifs-en-abbr" minwidth ='200' label="&en_abbr;"/>
</hbox>
<separator class='thin'/>
<hbox style="margin: 0" maxwidth="200">
<checkbox id="id-updateifs-ch-abbr" minwidth ='200' label="&ch_abbr;" />
</hbox>
</groupbox>
<script src="options.js"/>
<script
type="application/x-javascript"
src="chrome://zoteroupdateifs/content/scripts/options.js"/>
<script src="chrome://zotero/content/include.js"/>
</dialog>
it is weird, now it works, when I set the width of checkbox by using width ='250' .

Is it possible to bind the size of an accordion dynamically to the size of the expanded titled pane in JavaFX-8?

Such as the title suggests, i'm trying to bind the size of an Accordion dynamically to the size of the expanded TitledPane.
I tried to add an ChangeListener to the expandedPaneProperty of the accordion in the initialize method of the controller for the UI which contains the Accordion using following code:
private double prefHeight, prefWidth;
#Override
public void initialize(URL location, ResourceBundle resources) {
prefHeight = acc.getPrefHeight(); //double variables of controller
prefWidth = acc.getPrefWidth();
acc.expandedPaneProperty().addListener(new ChangeListener<Object>(){
#Override
public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) {
TitledPane pane = acc.getExpandedPane();
if(pane != null){
acc.setPrefHeight(prefHeight + pane.getPrefHeight());
acc.setPrefWidth(prefWidth + pane.getPrefWidth());
}
}
});
}
The Problem is, that this code leads to a NullPointerException at line 3, which might indicate that the property might not be instatiated at this moment.
Update: Problem concerning NullPointerException was solved, i didn't initialized the Accordion properly.
The code is still not working, though.
The corresponding FXML:
<Accordion fx:id="acc" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SettingsController">
<panes>
<TitledPane alignment="TOP_LEFT" animated="false" text="Alarm sound">
<tooltip>
<Tooltip text="Enables to choose an alarm sound." />
</tooltip>
<content>
<VBox alignment="TOP_CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" styleClass="box">
<children>
<HBox alignment="TOP_CENTER" styleClass="hbox">
<children>
<Button mnemonicParsing="false" text="Reset to default" />
<Button mnemonicParsing="false" onAction="#saveAndExitOnClick" text="Save and exit" />
</children>
</HBox>
<ListView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS" />
</children>
</VBox>
</content></TitledPane>
<TitledPane animated="false" text="Style">
<tooltip>
<Tooltip text="Enables to choose a style for the program." />
</tooltip>
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" styleClass="box">
<children>
<HBox alignment="TOP_CENTER" styleClass="h-box">
<children>
<Button mnemonicParsing="false" text="Reset to default" />
<Button mnemonicParsing="false" onAction="#saveAndExitOnClick" text="Save and exit" />
</children>
</HBox>
<ListView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" />
</children>
</VBox>
</content></TitledPane>
<TitledPane animated="false" text="Language">
<tooltip>
<Tooltip text="Enables to choose a style for the program." />
</tooltip>
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" styleClass="box">
<children>
<HBox alignment="TOP_CENTER">
<children>
<Button mnemonicParsing="false" text="Reset to default" />
<Button mnemonicParsing="false" onAction="#saveAndExitOnClick" text="Save and exit" />
</children>
</HBox>
<ListView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" />
</children>
</VBox>
</content>
</TitledPane>
<TitledPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" styleClass="box" text="Other settings">
<content>
<ToolBar maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" orientation="VERTICAL" styleClass="box">
<items>
<Button contentDisplay="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Recenter Window" />
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Reset program to default settings" />
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Load custom alarm sound" />
<Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Apply custom style" />
</items>
</ToolBar>
</content>
</TitledPane>
<TitledPane maxHeight="1.7976931348623157E308" prefWidth="200.0" text="About">
<content>
<TextArea editable="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Timer Program, written by QBW.
Version:
Fonts:
Font Awesome, License:
Alarm sounds:
Acknowledgement:
·Hans-Peter Habelitz for "Programmieren lernen mit Java"
·Christian Ullenboom for "Java ist auch eine Insel" and "Java SE8 Standardbibliothek"
·Anton Epple for "JavaFX 8 - Grundlagen und fortgeschrittene Techniken"
·The stackoverflow.com community
· Creators of alarm sound files:
·
·
·
·
·
· Creators of Font awesome
" wrapText="true" />
</content>
<tooltip>
<Tooltip text="Contains information about the program, its creator and license information" />
</tooltip>
</TitledPane>
</panes>
</Accordion>
How is it possible to solve that problem?

Menu Flyout XAML - C# - Windows 10 Mobile

I need my ToggleMenuFlyout occupy the full screen (on my mobile) but I am not able to.
Someone can help me?
My code:
AppBarButton x: Name = "FiltersPhone" Icon = "Filter" label = "Names">
                 <AppBarButton.Flyout>
                      <MenuFlyout>
                     <MenuFlyout.MenuFlyoutPresenterStyle>
                         <Style TargetType = "MenuFlyoutPresenter">
                             <Setter Property = "Background" Value = "Transparent" />
                             <Setter Property = "BorderThickness" Value = "0" />
                             <Setter Property = "Margin" Value = "0,4,0,0" />
                         </ Style>
                     </MenuFlyout.MenuFlyoutPresenterStyle>
                     <ToggleMenuFlyoutItem x: Name = "FlyoutItemDate" Text = "Today" tag = "Date"
                                            IsChecked = "True />
                 </ MenuFlyout>
                 </AppBarButton.Flyout>
             </ AppBarButton>
Thanks
<AppBarButton>
<AppBarButton.Flyout >
<MenuFlyout Placement="Full"></MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
Best of luck !

RadGrid change column header not working

I am trying to change the column header. When I do so it does not show the radgrid at all. If I comment the code inside of rdMain_PreRender the grid show up fine. Am I doing something wrong.
<telerik:RadGrid runat="server" ID="rdMain" AutoGenerateColumns="false" AllowPaging="true" Skin="Metro" OnPreRender="rdMain_PreRender" DataSourceID="MainSource" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView DataKeyNames="ID" CommandItemDisplay="None">
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" />
<telerik:GridBoundColumn DataField="Location" HeaderText="Location" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" />
<telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" />
<telerik:GridButtonColumn ConfirmText="Delete?" ConfirmDialogType="RadWindow"
ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
</telerik:RadGrid>
protected void rdMain_PreRender(object sender, EventArgs e)
{
var masterTableView = rdMain.MasterTableView;
var column = masterTableView.GetColumn("Phone");
column.HeaderText = "TelePhone";
masterTableView.Rebind();
}
Set the unique name of the columns in the grid and try using the next line of code in PreRender:
rdMain.Columns.FindByUniqueName("Phone").HeaderText = "TelePhone";
Hope it works.