JavaFX Sqlite检查TextField是否为空(JavaFX Sqlite check TextField wether its empty)
我现在正在努力检查我的所有InputFields他们
== ""
。我在这里找到了很多解决方案但不知何故它不起作用。
我有一个RegistrationModal和一个RegistrationController。
在模态中,我试图检查这样的字段:
public boolean RegisterUser(String user, String vorname, String nachname) throws SQLException { PreparedStatement preparedStatement = null; if (user == "" || vorname == "" || nachname == "") { System.out.println("Fill in all fields"); return false; } // Here follows the SQL query the prepared statement and exequte }
但它永远不会使用这个if语句,我不知道为什么?
我还尝试捕获控制器中的空元素:
public void Absenden(ActionEvent event) { try { if (registerModel.RegisterUser(txt_user.getText(), txt_vorname.getText(), txt_nachname.getText())) { if (registerModel.RegisterUser(txt_user.getText().trim().isEmpty(), txt_vorname.getText().trim().isEmpty(), txt_nachname.getText().trim().isEmpty())) { System.out.println("False! Do something?"); } // Here opens the new window with a notification Registration was successfull ((Node) event.getSource()).getScene().getWindow().hide(); }
在这里我有错误,这就是为什么两个if语句已经看起来很奇怪,我不得不在模型中自动生成一个新方法,使其与布尔值一起使用,但它仍然从未使用过这个if语句。
我试着只提供相关代码,否则会更多。
也许有人有个主意。
谢谢
I am struggling right now to check all my InputFields wether they
== ""
.I found many solutions here but somehow it doesnt work.
I have a RegistrationModal and a RegistrationController.
In the modal I tryed to check the fields like that:
public boolean RegisterUser(String user, String vorname, String nachname) throws SQLException { PreparedStatement preparedStatement = null; if (user == "" || vorname == "" || nachname == "") { System.out.println("Fill in all fields"); return false; } // Here follows the SQL query the prepared statement and exequte }
But it it never uses this if statement, I have no idea why?
I also tryed to catch the empty element in the controller:
public void Absenden(ActionEvent event) { try { if (registerModel.RegisterUser(txt_user.getText(), txt_vorname.getText(), txt_nachname.getText())) { if (registerModel.RegisterUser(txt_user.getText().trim().isEmpty(), txt_vorname.getText().trim().isEmpty(), txt_nachname.getText().trim().isEmpty())) { System.out.println("False! Do something?"); } // Here opens the new window with a notification Registration was successfull ((Node) event.getSource()).getScene().getWindow().hide(); }
Here I had errors so thats why two if statement which already seems weird, I had to autogenerate a new method in model to make this work with booleans, but still it never used this if statement.
I tryed to give only relevant code, otherwise it would be much more.
Maybe someone has an idea.
Thanks
原文:https://stackoverflow.com/questions/36134119
最满意答案
我找到了有效的解决方案。 通过检查Application.Ready属性,您可以确定excel文件是否处于编辑模式。 不幸的是,如果文件处于编辑模式,这仍然会引发错误。 我能够通过使用try语句来查询和捕获pywintypes.com_error异常来解决这个问题。
我只是通过添加一个新函数来检查状态来编辑我的代码:
from pywintypes import com_error def isReady(XL): try: return XL.Ready except com_error: return False def buttonShow(XL): if isReady(XL): XL.Visible ^= 1
这似乎有效。 现在,如果excel应用程序仍处于编辑模式,则该按钮根本不执行任何操作。 如果excel应用程序未处于编辑模式,它将按预期工作并切换可见性。
I found an effective solution. By checking the Application.Ready attribute you can determine if the excel file is in edit mode. Unfortunately, if the file is in edit mode, this still throws an error. I was able to work around by using a try statement to query, and catching the pywintypes.com_error exception.
I simply edited my code by adding a new function to check the status:
from pywintypes import com_error def isReady(XL): try: return XL.Ready except com_error: return False def buttonShow(XL): if isReady(XL): XL.Visible ^= 1
This seems to work. Now, if the excel application is still in edit mode, the button simply does nothing. If the excel application is not in edit mode, it works as expected and toggles the visibility.
相关问答
更多-
在IE9上,您需要降低安全设置以使脚本正常工作: IE9 -> Internet Options -> Security -> Trusted Sites : Low IE9 -> Internet Options -> Security -> Internet : Medium + unchecked Enable Protected Mode IE9 -> Internet Options -> Security -> Restricted Sites : unchecked En ...
-
您必须在打开文档后激活页眉/页脚窗格。 语言Visual Basic。 将语法更改为python ActiveDocument.ActiveWindow.Panes(1).View.SeekView=wdSeekCurrentPageHeader 对于标题和 ActiveDocument.ActiveWindow.Panes(1).View.SeekView = wdSeekCurrentPageFooter 对于页脚 然后搜索/替换 要将窗格更改为主要部分使用 ActiveDocument.Ac ...
-
我实际上是通过借用这篇关于用VBA做同样事情的MSDN文章来解决这个问题: http://support.microsoft.com/default.aspx?scid=KB;en-us;q213489 以下现在完美地运作: xl = win32com.client.gencache.EnsureDispatch('Excel.Application') xl.Visible = True xl.RegisterXLL('C:/path/addin.xll') wb = xl.Workbooks.Open( ...
-
您可以在创建图表expression.AddChart(Type, Left, Top, Width, Height)时指定位置expression.AddChart(Type, Left, Top, Width, Height)请参见此处 。 如果您不想在工作表中嵌入图表,可以创建图表工作表: wb.Worksheets.Add(Type:=xlChart) 警告:Microsoft.interop.Excel不是win32com,但应该可以工作。 You can specify the location ...
-
sheet.Range("A8").Hyperlinks.Item(1).Address sheet.Range("A8").Hyperlinks.Item(1).Address
-
win32com打开和发送excel进程之间的交互(Interaction between open and dispatched excel processes, win32com)[2024-04-06]
您应该设计脚本,假设只能运行一个Excel实例,尽管它可以包含多个工作簿。 如果您使用GetObject (而不是GetActiveObject ),那么win32com将返回现有应用程序的句柄(如果存在),或者如果不存在则启动应用程序。 所以你不需要if / else。 此外,在设计方面,这意味着您应该有一种方法来跟踪打开哪些工作簿 ,并仅关闭那些工作簿 ,以便Excel应用程序的最终状态与启动脚本时的最终状态相同。 因此,每个工作簿都有一个ExcelDocument实例,每个实例都使用GetObject ... -
我找到了有效的解决方案。 通过检查Application.Ready属性,您可以确定excel文件是否处于编辑模式。 不幸的是,如果文件处于编辑模式,这仍然会引发错误。 我能够通过使用try语句来查询和捕获pywintypes.com_error异常来解决这个问题。 我只是通过添加一个新函数来检查状态来编辑我的代码: from pywintypes import com_error def isReady(XL): try: return XL.Ready except com_error ...
-
似乎问题在于win32com模块。 使用comtypes模块的等效代码正确运行: >>> from comtypes.client import CreateObject >>> Aquator = CreateObject("Aquator.Application") >>> Database = Aquator.LoadDatabase(r"D:\Shared", "AquatorExcel.mdb") >>> Project = Aquator.LoadProject(Database, "A sim ...
-
COM异常是由于缺少文件名参数,因为找不到f = r"./input.xlsx" 。 如果你使用Excel 2013+,你会收到一个更精确的异常消息,错误代码略有不同: (-2147352567,'异常发生。',(0,'Microsoft Excel',“抱歉,我们找不到./input.xlsx。它是否可能被移动,重命名或删除?”,'xlmain11.chm' ,0,-2146827284),无) 虽然您的路径在指向被调用的.py脚本所在的目录的Python本机上下文中有效,但它不与外部API(如Windo ...
-
我通常做的是我在Excel中记录宏,而不是尝试在Python中重新破解VB。 要删除内容,我得到类似的东西,不应该很难将其转换为Python: Range("H5:J26").Select Selection.ClearContents 在Python中它应该是这样的: self.xl.Range("H5:J26").Select() self.xl.Selection.ClearContents() 工作范例: from win32com.client.gencache import EnsureDi ...