I am using JDateChooser with JCalendar in application. User should choose the date in date chooser and date should be updated in JTextFieldDateEditor. However, I can't seem to get the PropertyChangeListener to work.
I have checked it on stackoverflow as well, found Is it possible to detect a date change on a JCalendar JDateChooser field? which seems to be the exact same problem as I am having. I copied the code through from there, but I still get 'cannot find symbol - class PropertyChangeListener' error. I imported whole awt.event and JCalendar libraries. I am absolutely clueless as to what is wrong with my code.
Here's what I have written so far
datum = new Date ();
klik = new JDateChooser (datum)
klik.getDateEditor().addPropertyChangeListener( new PropertyChangeListener()
{
#Override
public void propertyChange(PropertyChangeEvent e)
{
if ("date".equals(e.getPropertyName()))
{
System.out.println(e.getPropertyName()
+ ": " + (Date) e.getNewValue());
}
}
});
which is basically copy-paste from the link above, but it seems reasonable to me
Thanks for your help :)
Related
#Override
public void onAccessibilityEvent(final AccessibilityEvent event) {
Date date = new Date(event.getEventTime());
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
String time = format.format(date);
String reqTime = "25/11/2018 04:39";
if (reqTime.equals(time)) {
Log.d("MyAccessibilityService", "onAccessibilityEvent");
if (getRootInActiveWindow() == null) {
return;
}
AccessibilityNodeInfoCompat rootInActiveWindow = AccessibilityNodeInfoCompat.wrap(getRootInActiveWindow());
//Inspect app elements if ready
//Search bar is covered with textview which need to be clicked
List<AccessibilityNodeInfoCompat> clickOnQuestionMark = rootInActiveWindow.findAccessibilityNodeInfosByViewId("com.whatsapp:id/menuitem_search");
if (clickOnQuestionMark.isEmpty() || clickOnQuestionMark == null) {
return;
}
AccessibilityNodeInfoCompat clickMark = clickOnQuestionMark.get(0);
clickMark.performAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
I am using this code for simuating clicking whatsapp search button, but when I opened whatsapp window on 25-11-2018 at 4:39 nothing happened. The code was working fine when no time was alloted. But problem was that everytime whatsapp was opened the search button would get clicked. How to click on the search button only when whatsapp is opened at a specific time?
You can convert to LocalDate
LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
and use equals method to specific LocalDate
Compares this LocalDate with another ensuring that the date is the same.
Only objects of type LocalDate are compared, other types return false.
Ok, so after trying really hard for some days i am still not able to make this work.
This is the problem: I have a JSP which hosts a Google chart that is going to be constructed from data that is going to be sent through a Servlet. I'm using the Google Visualization Java libraries to implement this servlet.
Then i have this helper function that, taking some data stored in a list of objects, constructs a datatable. Following is the class that implements said function:
public class DataTableGenerator {
public static DataTable generateDatatable(List<AccesoUrl> accesos) {
DataTable data = new DataTable();
ArrayList<ColumnDescription> cd = new ArrayList<>();
cd.add(new ColumnDescription("fecha", ValueType.DATE, "Fecha"));
cd.add(new ColumnDescription("navegador", ValueType.TEXT, "Navegador"));
cd.add(new ColumnDescription("ip", ValueType.TEXT, "IP"));
cd.add(new ColumnDescription("os", ValueType.TEXT, "Sistema Operativo"));
data.addColumns(cd);
try {
for(AccesoUrl acceso : accesos) {
GregorianCalendar calendario = new GregorianCalendar();
calendario.setTimeZone(TimeZone.getTimeZone("GMT"));
data.addRowFromValues(calendario, acceso.getNavegador(), acceso.getIp(), acceso.getSistemaoperativo());
}
} catch (TypeMismatchException e) {
System.out.println(e);
}
return data;
}
}
Now, this piece of code should work, but instead i am getting this exception on my web server:
com.google.visualization.datasource.base.TypeMismatchException: Value type mismatch.
at com.google.visualization.datasource.datatable.value.ValueType.createValue(Unknown Source)
at com.google.visualization.datasource.datatable.DataTable.addRowFromValues(Unknown Source)
I'm at wit's end now. I have tried every variation i could find on Google so that my JSP displays this data on a Google Table type of chart. I have tried sending a date as a string, a date as a string formatted as a javascript date (i.e "Date(2015,4,4)" or "new Date(2015,4,4)"). I have tried using the DateValue object that comes with the java visualization library to construct the date as well (i.e new DateValue(2015,4,4)). I have also tried passing a Java Date as well. Nothing works, everything throws a TypeMismatchException.
I am sure it's the date that's giving me trouble because as soon as i remove the date column from the datatable everything runs fine with no exception and i can get my data displayed on the Google chart table.
So can anybody please tell me what exactly do i have to do in my Java code to be able to construct a datatable with a date cell?
Even I faced same issue. But it seems addRowFromValues() doesn't support DateValue(). I siwtched to addRow(TableRow). Didnt see any error's.
You can use something like below,
Sample Code:
DataTable data = new DataTable();
ArrayList<ColumnDescription> cd = new ArrayList<ColumnDescription>();
cd.add(new ColumnDescription("date", ValueType.DATE, "Executed Date"));
cd.add(new ColumnDescription("value", ValueType.NUMBER, "Duration "));
data.addColumns(cd);
TableRow tr = new TableRow();
tr.addCell(new DateValue(2015,7,7));
data.addRow(tr);
I am new at java swing because of that in my project i couldn't connect and get data from Microsoft sql server to Jtable.
But in this time I have just done it but I still interesting that if I don't use code, if I want to use that without code what should I do? In 'Netbeans', if you click table contents there is a way for import data to form. that is the point what I couldn't.
I tried to use this button(import data to form) and I showed my sqlserver.jar and I couldn't.
I think is that what you want:
http://fahdshariff.blogspot.com.br/2010/02/display-any-resultset-in-jtable.html
But in java, you will not get without some code.
I ran into a similar problem and the code below helped so I could retrieve the desired data. Edit the code so it will get the information you want it to retrieve.
private class RemoveBookings implements ActionListener {
String bookingID;
#Override
public void actionPerformed(ActionEvent ae) {
if (theMainViewDisplay.bookingData.getSelectedRow() != -1) {
final DefaultTableModel model = (DefaultTableModel) theMainViewDisplay.bookingData.getModel();
// Get stored varible
int index = theMainViewDisplay.bookingData.getSelectedRow();
System.out.println(index);
theMainViewDisplay.bookingID = model.getValueAt(index, 0).toString();
theMainViewDisplay.pickUpLocation = model.getValueAt(index, 2).toString();
theMainViewDisplay.dropOffLocation = model.getValueAt(index, 3).toString();
System.out.println(theMainViewDisplay.bookingID);
// Remove booking from database
model.removeRow(theMainViewDisplay.bookingData.getSelectedRow());
theBackendModel.thePowList.remove(bookingID);
}
}
}
I'm working with Java Application with JFormattedTextField. I have some problems that:
How to set JFormattedTextField with can accept "/" and "-"
I want to set jformattedtextfield value and text to null or "" after entering wrong format.
Example:
2.1.JFormattedTextField ftf .... with format ("yyyy-MM-dd")
2.2. Input right format: 1990-5-6
2.3. Leave ftf
2.4. Then focus ftf and input wrong format: 5-6-1990
2.5. Leave ftf then it recognize wrong format but return something else
But what I want is that I must be null or empty.
How can I do it?
Any suggestions would be appreciated!
This is my first answer on this forum and I hope I don't mess up. For the first question, you can use MaskFormatter. This will also ensure that the value is never entered wrong.
new JFormattedTextField(createFormatter("####-##-##"));
private static MaskFormatter createFormatter(String s) {
MaskFormatter formatter = null;
try {
formatter = new MaskFormatter(s);
formatter.setPlaceholderCharacter('0');
} catch (java.text.ParseException exc) {
System.err.println("formatter is bad: " + exc.getMessage());
System.exit(-1);
}
return formatter;
}
I'm working with Jasper Reports, version 3.7.5.
I'm trying to use a custom FormatFactoy implementation to handle the case of an empty string representation ( "" ) of the XML data for a date field. I implemented a class implementing FormatFactory which should handle that.
public class InvoicePrintFormatFactory implements FormatFactory {
#Override
public DateFormat createDateFormat(String string, Locale locale, TimeZone tz) {
DateFormat format = new SimpleDateFormat(string, locale){
#Override
public Date parse(String source) throws ParseException {
if((source == null) || (source.equals("")))
return null;
return super.parse(source);
}
}
return format;
}
#Override
public NumberFormat createNumberFormat(String string, Locale locale) {
NumberFormat format = new DecimalFormat(string){
#Override
public Number parse(String source) throws ParseException {
if((source == null) || (source.equals("")))
return null;
return super.parse(source);
}
}
return format;
}
}
In my JRXMLDatsource I set the source format patterns like this:
JRXmlDataSource reportSource = new JRXmlDataSource(document, headRecordPath);
reportSource.setDatePattern("mm.dd.yy");
reportSource.setNumberPattern("####0.00");
and of course handing over a instance of my FormatFactory
reportParams.put(JRParameter.REPORT_FORMAT_FACTORY, new InvoicePrintFormatFactory());
Everything works fine here if the datasource XML does not contain "" values for a date field. But if that happens I get the following exception:
org.apache.commons.beanutils.ConversionException: Unparseable date: ""
at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:241)
at org.apache.commons.beanutils.locale.LocaleConvertUtilsBean.convert(LocaleConvertUtilsBean.java:285)
at net.sf.jasperreports.engine.data.JRAbstractTextDataSource.convertStringValue(JRAbstractTextDataSource.java:69)
at net.sf.jasperreports.engine.data.JRXmlDataSource.getFieldValue(JRXmlDataSource.java:313)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:821)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:785)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1482)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:126)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:946)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:84)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
at com.lmobile.crm.invoicePrinter.operator.Printer.operate(Printer.java:219)
at com.lmobile.crm.invoicePrinter.service.InvoicePrintService.CreatePrintOrder(InvoicePrintService.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at za.co.softco.rest.ReflectionService.handle(ReflectionService.java:253)
at za.co.softco.rest.ReflectionHandler.handle(ReflectionHandler.java:94)
at za.co.softco.rest.RestWorker.handlePost(RestWorker.java:477)
at za.co.softco.rest.RestWorker.handleClient(RestWorker.java:289)
at za.co.softco.rest.RestWorker.run(RestWorker.java:152)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.text.ParseException: Unparseable date: ""
at java.text.DateFormat.parse(DateFormat.java:337)
at net.sf.jasperreports.engine.util.JRDateLocaleConverter.parse(JRDateLocaleConverter.java:84)
at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:230)
... 23 more
If I debug the method calls for my custom FormatFactory implementation I observe that both methods are not being called until running into the exception. Thus I assume that Jasper is using the default FormatFactory for some reason.
What did I do wrong here? Do anybody have an idea about this?
Thanks in advance.
I found a tutorial and it worked for me, basically i see some differences between your code and the code in the tutorial.
First. Instead of implement FormatFactory you must extend DefaultFormatFactory
Second. You must not pass the class as a parameter, only configure it in the class path of the iReport.
This is the link post to jasperreports community
The answer was posted by the user thangalin
I will copy and paste the answer just in case the post gets lost.
The following seems to work:
Click Window >> Preferences >> Select Capabilities >> Check Development >> Click OK
Next:
Open the Project Explorer Right-click Project name Select Properties
Select Java Build Path Click the Source tab Click Add Folder Select
Create New Folder Set Folder Name to: src Click Finish Select src
Click OK Set Default output folder: Project Name/build Click OK
Create a report as usual (with a text field that uses a date, either
a parameter or a field),
Then:
Select the report in the Outline panel
Open the Properties panel
Set Format Factory Class to: com.company.reports.ReportFormatFactory
Next, create some source code inside the "src" directory in a package (folder) named "com.company.reports". Paste the following into a file named "ReportFormatFactory.java" that is saved in that directory:
import java.text.DateFormat;
import java.util.Locale;
import java.util.TimeZone;
import net.sf.jasperreports.engine.util.DefaultFormatFactory;
/**
* Delegates creation of date and number formatters to JasperReports' default
* formatters. This class ensures that dates are formatted consistently across
* all reports.
*/
public class ReportFormatFactory extends DefaultFormatFactory {
/**
* Returns a DateFormat instance that creates dates in YYYY/MM/dd format.
*
* #param pattern Unused.
* #param locale Passed to the DefaultFormatFactory instance.
* #param timezone Passed to the DefaultFormatFactory instance.
*
* #return An object that can format dates.
*/
#Override
public DateFormat createDateFormat(
String pattern, Locale locale, TimeZone timezone ) {
return super.createDateFormat( "YYYY/MM/dd", locale, timezone );
}
}
When you run the report, the date should be formatted as YYYY/MM/dd.
If you want to change the format (e.g., to "dd/MM/YYYY"), update the date format line in the source code and then restart Jaspersoft Studio (the classloader does not seem to reload the ReportFormatFactory class after modification).