Problems making JavaFX TextField and TextArea editable - javafx-2

I have a JavaFX Application which opens an auxiliary Stage. The Stage itself contains a TextArea and a TextField, both marked as editable in Scene Builder, and neither of them with any bindings for the TextProperty (as far as I know). Even so, I am unable to type anything into these fields.
What might be blocking the editing?
The relevant FXML is as follows:
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<Label prefHeight="26.0" prefWidth="89.0" text="Query name:" textAlignment="RIGHT" />
<TextField fx:id="queryNameTextField" prefHeight="26.0" prefWidth="518.0" />
</children>
</HBox>
With some further tinkering I have noticed that the new window I open does not always have focus, even when the TextField itself does! I say this because the title of the window is greyed out.

Related

Hiding Tab(s) in MaterialDesign Tabablz TabablzControl

I would like to bind a TabItem's visibility property to a bool property in my viewmodel (via converter, true=visible false=collapsed), but the visibility property on the TabItem does not hide the tab. I don't want to hide all of the tab, just individual ones.
Does anyone know how this can be achieved?
I wanted to have something similiar. I asked the developer about it, but this is not possible with Dragablz (which is Tabablz). The TabItem itself is not used in dragablz.
A workaround for this could be using materialdesign radiobuttons as tab headers instead of dragablz. Radio buttons can be collapsed.
<StackPanel Orientation="Horizontal" Margin="4">
<RadioButton x:Name="FirstTab" Style="{StaticResource MaterialDesignTabRadioButton}" Margin="4" Visibility="Collapsed" IsChecked="True" Content="FIRST" />
<RadioButton Style="{StaticResource MaterialDesignTabRadioButton}" Margin="4" IsChecked="False" Content="SECOND" />
<RadioButton Style="{StaticResource MaterialDesignTabRadioButton}" Margin="4" IsChecked="False" Content="THIRD" />
</StackPanel>
now you just have to create some grids below them, which have their visibility bound to the IsChecked attribute of the corresponding radio button. This way you can show only the grid which is bound to the currently selected radio button. You need a bool2visibility converter, maybe the default one shipped with wpf works (the one in my example is a custom one).
<Grid Visibility="{Binding IsChecked, Source={x:Reference FirstTab}, Converter={StaticResource Bool2VisibilityConverter}}">

Richfaces: menu key binding

I got a richface issue that rather looks very easy, but i can't find the answer.
I want to acces a (dropdown)menu with keybindings. Once the menu has focus i can use the arrow buttons without a problem. I just cant get the 'focus' on my menu with a hotkey
XHTML:
<rich:dropDownMenu
binding="#{menuBarBean.menuBar}"
id="main-menu"
showEvent="mouseup"
onclick="showMenu();"
/>
<rich:hotKey enabledInInput="true" key="ctrl+M" onkeyup="displayMenu()" preventDefault="true" />
JavaScript:
function displayMenu(){
#{rich:component('main-menu')}.show();
**// Do something that sets focus on the richface menu component**
}
In short:
How to get the focus on
#{rich:component('main-menu')}
with:
<rich:hotKey />
jQuery has a .focus() method that focuses things:
#{rich:component('main-menu')}.element.focus();

javafx new "screen" in same tab

I have a piece of code like this :
<Tab text="A" fx:controller="myController" xmlns:fx="http://javafx.com/fxml">
<content>
<VBox>
<children>
<fx:include fx:id="topTab" source="../top-tab.fxml"/>
<AnchorPane prefHeight="600" VBox.vgrow="ALWAYS">
<!-- insert code here -->
</AnchorPane>
<AnchorPane id="bottom_anchor" prefHeight="250" />
<fx:include fx:id="bottomTab" source="../bottom-tab.fxml"/>
</children>
</VBox>
</content>
</Tab>
Right now, the 'insert code here' part has a list of links to youtube videos. The idea is, when the user clicks on one of these links, to show IN THE SAME AnchorPane the video and the list disappears. It would be like another screen (with a nice transition if possible) that appears while the list disappears, all inside this AnchorPane as I need to stay there.
I have thought about using a StackPane and making things visible or invisible as needed, but that seems... strange.
As I am new to JavaFX, any answer explained as to a 9-year-old would be appreciated
Thank you all !
Easiest way I think is to add 2 AnchorPanes inside the AnchorPane you already have. Let's call them pList and pContent. Then play with the visible property of them.
To make a nice transition you can do something like this:
FadeTransition showTransition = new FadeTransition(Duration.seconds(.1), pList);
showTransition.setFromValue(0.0f);
showTransition.setToValue(1.0f);
showTransition.play();
Do it the other way for pContent.

How to Update Image on Button Click Command

View has a button and Image control.I have bound the button command to a delegateCommand on the ViewModel, which opens a file dialog for the user to choose an Image.The Context "object" for View contains a property "Icon" which is of type byte[].I have bound the Icon to the Image control.The question is how do i display the selected image file on the image control?.
Xaml:
<Button x:Name="dlgIconbtn" Command="{Binding OpenFileCommand}" Content="Choose Icon" MaxWidth="120" Grid.Row="3" Grid.Column="1" Margin="5"/>
<Image Grid.Row="3" Margin="5" Grid.Column="3" Source="{Binding AppItem.Icon,Converter={StaticResource imgConverter}}"
Width="25" Height="25"/>
I solved it using a property "ImgSource" in the viewModel which is bound to the source of the ImageControl.Whenever a user selects an image using the button command i set the image file contents to the "ImgSource" and it works.
I assume Your Converter is working fine.
Now when OpenFileCommand fires user selects image and you update App.Icon property with new Byte[].
Now please RaiseProperty changed event on Icon so Binding get refreshed.
I do not think you need any Code here.
if still not working then please update you Question with full code XAML + ViewModel

Exporting Gridview to Excel in web app

Hopefully you guys can help me out. I tried a lot of different things and cant get this working.
I have a gridview as below in a update panel:
<asp:UpdatePanel ID="udpReport" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView runat="server" ID="preferenceReportGrd" AutoGenerateColumns="false"
AutoGenerateSelectButton="false" CaptionAlign="Top" EnableSortingAndPagingCallbacks="false" HorizontalAlign="left" CssSelectorClass="gvwPrefReport">
<Columns>
<asp:BoundField ReadOnly="true" DataField="ClientName" HeaderText="Company Name" />
<asp:BoundField ReadOnly="true" DataField="typeDescription" HeaderText="Preference" />
<asp:BoundField ReadOnly="true" DataField="defaultValue" HeaderText="Default Preference" />
<asp:BoundField ReadOnly="true" DataField="previousPreferenceValue" HeaderText="Previous Preference" />
<asp:BoundField ReadOnly="true" DataField="selectedValue" HeaderText="New Preference" />
<asp:BoundField ReadOnly="true" DataField="lastUpdated" HeaderText="Date Last Edited" />
</Columns>
</asp:GridView>
<div>
<user:MsgLine runat="server" ID="MsgLine1" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
I am trying to export this gridview out to excel. There is a button which the user clicks on it calls the on_click method for that button and in this on_click i have the following:
string attachment = "attachment; filename=Employee.xls";
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
preferenceReportGrd.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
I get nothing from this tried debugging it seems that when i mouse over stw.tostring() all the values for the gridview are there but nothing gets written out.
Yes. within the update panel tag excel export is not working. I face the same problem.
To solve this use the following code in end of the update panel tag
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="BtnExport" />
</Triggers>
</asp:UpdatePanel>
it works even within the update panel also
If the GridView and/or the button is within in update panel with an async postback, I do not believe you can change the response headers or information. Try running it again with a full postback on the button trigger and see what happens. Your code did not look incorrect, but I've not tried it...
Take a look at this samples...
1. c-sharpcorner
2. Matt Berseth
3. Code Project
Check your content types and for a PostBackTrigger on the exporting button.
For Excel 2003
Response.ContentType = "application/vnd.ms-excel
For Excel 2007
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
You can check out this blog post for the source of my content types.
EDIT: From your comments:
You need to set a PostBackTrigger on the panel that contains the button doing the export, not the panel that contains the GridView.
EDIT EDIT: Your file-is-not-what-it-says-it-is error is due to a feature called Extension Hardening, present in Excel 2007. Check this StackOverflow question for more info; I linked to a blog post describing the reasoning for this error and a possible workaround.
The way I was able to work around this in a simple page that I was working on was to have a hidden gridview outside of the updatepanel and set it equal to the gridview in the update panel so that they are the same (except for the new one being hidden). Then export this hidden grid to Excel the same way that you were doing it before.
One issue with doing it this way is that the export hyperlink needs to be outside of the update panel as well which means that you might not be able to put the export hyperlink where you want it.
Granted this is probably not the best way to do it, it got me around this issue at the time. Hope it helps.

Resources