Question: Where can I get a list of all UIDefaults properties that exist in Swing?
I know of the possibility to write a small snippet of code that just extracts and displays them but I would like to know whether the list I get that way is really complete.
When I do so, I get 636 properties for the Metal L&F, 613 for Windows L&F and 550 for the Motif one. Another source on the net puts a list of 795 entries although it has some incorrect additional entries. But perhaps even the metal l&f does not set all it actually could.
I have difficulties to believe there really doesn't exist an official list of possible properties from sun.
Not all properties come from Sun. For example, Mac OS lists 654 properties + 51 specific to apple.laf.AquaLookAndFeel. Here's some code if others want to submit results:
import javax.swing.UIDefaults;
import javax.swing.UIManager;
public class CountUIDefaults {
public static void main(String[] args) throws Exception {
System.out.println(System.getProperty("os.name")
+ " " + System.getProperty("os.version")
+ " " + System.getProperty("java.version"));
UIManager.LookAndFeelInfo[] lfa =
UIManager.getInstalledLookAndFeels();
for (UIManager.LookAndFeelInfo lf : lfa) {
UIManager.setLookAndFeel(lf.getClassName());
UIDefaults uid = UIManager.getLookAndFeelDefaults();
System.out.println("***"
+ " " + lf.getName()
+ " " + lf.getClassName()
+ " " + uid.size() + " entries");
}
}
}
Mac OS X 10.5.8 1.6.0_17
*** Metal javax.swing.plaf.metal.MetalLookAndFeel 636 entries
*** Nimbus com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel 1052 entries
*** CDE/Motif com.sun.java.swing.plaf.motif.MotifLookAndFeel 550 entries
*** Mac OS X com.apple.laf.AquaLookAndFeel 705 entries
Ah, well, I should have thought about that one more intensively.
Of course the list of "valid" properties is directly dependent on the used l&f and what you want to do with it:
Write an own l&f
In this case, the "official list" is the list of properties you get from the l&f you inherit. In case of MetalLookAndFeel, it's the 636 entries you can retrieve, I haven't tried the numbers for the more common BasicLookAndFeel and SynthLookAndFeel - I guess they can be checked by putting a more or less empty Subclass of those and running the code presented above.
Modify an existing l&f
In this case running the code for the l&f used yields everything that can be modified.
So in the end, the solution is that there cannot be a thing like an "official overall list" as such a one can only be put based on some specific l&f, in which case the code above will yield what one wants to know.
Linux 2.6.31-19-generic 1.6.0_0
*** Metal javax.swing.plaf.metal.MetalLookAndFeel 642 entries
*** CDE/Motif com.sun.java.swing.plaf.motif.MotifLookAndFeel 556 entries
*** GTK+ com.sun.java.swing.plaf.gtk.GTKLookAndFeel 566 entries
Related
I know of three JFR Event types: Instant Event, Duration Event, and Sample Event, but how to identify JFR event types.
I try to distinguish them from the configuration, but it seems doesn't work, for example, jdk.ObjectAllocationInNewTLAB, it only need to configure whether to enable, seems to be an Instant Event, but is actually a Sample of the Event.
This is important to me because I want to analyze with full information, not samples
You can see what options an event type supports by using the setting descriptor:
for(EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
System.out.println(type.getName());
System.out.println("Settings:");
for (SettingDescriptor s : type.getSettingDescriptors()) {
String def = " (default: " + s.getDefaultValue() + ")";
System.out.println(" " + s.getName() + def);
}
System.out.println();
}
It's also possible to list event metadata, including settings, using the 'jfr' tool located in JAVA_HOME/bin. For JDK 11, you must supply the file you want metadata to be printed for:
$ jfr metadata recording.jfr
For JDK 17, you can omit the file and you will get the event types for the JDK the tool is located in:
$ jfr metadata
I have a very strange problem with NullPointerException. Code example is as follows:
...
... public String[] getParams(...) {
... ...
... ...
143 return new String[] {
144 getUserFullName(),
145 StringUtil.formatDate(sent),
. tiltu,
. StringUtil.initCap(user.getName()),
. vuosi.toString(),
. asiatyyppi[0] + " " + lisatiedot[0],
. asiatyyppi[1] + " " + lisatiedot[1],
. alaviitteet[0],
152 alaviitteet[1]};
153 }
Now, I have got an issue from production having a stack trace:
java.lang.NullPointerException
at package.EmailService.getParams(EmailService.java:143)
...
I am unable to produce that kind of stack trace myself. It maybe some environment issue that for some reason line numbers don't match. If I have null references on any variable stack trace points to that specific line but never to line 143.
But what I want to ask is: is it possible to produce NullPointerException at line 143 specifically?
The line number in the stack trace comes from the LineNumberTable attribute in the class file. (See JVM specification)
It would be no problem to output the right line number for a subexpression - all the compiler has to do is to say that from byte-code index x to y, there is a correspondence with source code line z.
But up to and including Java 1.7 there was a bug in the compiler, that was fixed in 1.8:
https://bugs.openjdk.java.net/browse/JDK-7024096
A DESCRIPTION OF THE PROBLEM : linenumbertable in compiled code only
has line numbers for starts of statements. When a statement is using
method chaining or other "fluent Interface" style API's a single
statement can span tens of lines and contain hundreds on method
invocations.
Currently an exception throw from within any of these methods will
have the linenumber of the first line of the enclosing statement which
makes it very hard to debug which method call is having a problem.
linnumbertable should have correct line numbers for every method
invocation.
--
BT2:EVALUATION
It seems simple enough to fix this, but its kinda risky at the end of
the jdk7 development cycle, targetting to jdk8.
So in 1.7, you would get the wrong reported line number for these kind of subexpressions (if they occurred within the same method though - if you invoked another method in a subexpression, and that other method caused a NullPointerException, you would see it reported there - this is probably why the bug isn't always a big problem)
One way you could work around this is by taking the Java 8 compiler to compile your source code, and use the flags javac -source 1.7 -target 1.7. But it would be better and safer to upgrade your prod environment to 1.8.
Consider your original code which defines a new String array:
return new String[] {
getUserFullName(),
StringUtil.formatDate(sent),
tiltu,
StringUtil.initCap(user.getName()),
vuosi.toString(),
asiatyyppi[0] + " " + lisatiedot[0],
asiatyyppi[1] + " " + lisatiedot[1],
alaviitteet[0],
alaviitteet[1]};
}
If any of the elements of the inline array should trigger a NullPointerException the JVM will interpret the Exception as having occurred on the line where the definition began. In other words, the JVM will view the above code as being the same as:
return new String[] { getUserFullName(), StringUtil.formatDate(sent), tiltu, StringUtil.initCap user.getName()), vuosi.toString(), asiatyyppi[0] + " " + lisatiedot[0], asiatyyppi[1] + " " + lisatiedot[1], alaviitteet[0], alaviitteet[1]}; }
where everything is on one line.
If you really want to handle NullPointerExceptions here, you should define the variables outside the instantiaition.
When Google you will find lot of materials to find all the supported Locales by Java. But its all confusing.
For example [http://sanjaal.com/java/tag/java-locale-tutorial/] show an output of 210 locales. But when I run the same program I get only 155. I don;t get for example ta_IN. si_LK is not output by any program.
Can someone please clear the air?
I use JDK/JRE 1.7
http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html gives 111 entries.
I have a Spring Application which supports i18n and our customers can put their own localisations. What I am trying to do is to provide a list of all locales for them to select their one from.
Oh! this is confusing. Local.getISOCountries() provide LK as a country and Locale.getISOLanguages(); provide si as a language .... but si_LK which is a valid locale is not given in Locale.getAvailableLocales();
Locale loc = new Locale("ta", "IN"); // ta_IN, si_LK
System.out.printf("Name: %s%n"
+ "Country: %s; %s - %s%n"
+ "Language: %s; %s - %s%n"
+ "Script: %s - %s%n",
loc.getDisplayName(Locale.ENGLISH),
loc.getCountry(), loc.getISO3Country(), loc.getDisplayCountry(Locale.ENGLISH),
loc.getLanguage(), loc.getISO3Language(), loc.getDisplayLanguage(Locale.ENGLISH),
loc.getScript(), loc.getDisplayScript(Locale.ENGLISH));
Name: Tamil (India)
Country: IN; IND - India
Language: ta; tam - Tamil
Script: -
Name: Sinhalese (Sri Lanka)
Country: LK; LKA - Sri Lanka
Language: si; sin - Sinhalese
Script: -
Also it is possible to provide support for ones own locale (since Java 7 I believe). I made it for Esperanto, and it is doable (LocaleProvider). But in your case all might be there.
SimpleDateFormat f = new SimpleDateFormat("EEEE", loc);
System.out.println("Weekday: " + f.format(new Date()));
Unfortunately shows "Tuesday," so one needs to implement the language formats and such.
I found a project for serbo-croatian/bosnian.
The code you found on internet use the next function to extract all the locales:
Locale list[] = DateFormat.getAvailableLocales();
If we read the documentation for that function:
Returns an array of all locales for which the get*Instance methods of this class can return localized instances. The returned array represents the union of locales supported by the Java runtime and by installed DateFormatProvider implementations. It must contain at least a Locale instance equal to Locale.US
So we can understand that the number of locales returned depends on your runtime version, and your DateFormatProvider.
For example in my machine with JDK 1.6.0_27 I get 152 results.
To provide a list of all ISO countries in your JAVA Version try the following:
public static void main(String[] args) {
String[] locales = Locale.getISOCountries();
for (String countryCode : locales) {
Locale obj = new Locale("", countryCode);
System.out.println("Country Code = " + obj.getCountry()
+ ", Country Name = " + obj.getDisplayCountry());
}
}
This way you can provide a complete list of all countries but it is still dependend on the current ISO country list of your JDK.
Another way would be to use a REST-API from a provider like: https://restcountries.eu/rest/v2/all from https://restcountries.eu/
This way your program is independent of the JDK you use and is always up2date (if your chosen provider is reliable).
Is it possible to programmatically determine if the Windows antivirus solution is up to date within Java?
You can use the productUptoDate property of the AntiVirusProduct WMI Class. Here you have some samples (in C# and Delphi) of use and the location(the namespace depends of the Windows version) of such class.
Detect Antivirus on Windows using C#
Getting the installed Antivirus, AntiSpyware and Firewall software using Delphi and the WMI
for access th WMI service from Java you can use jinterop or jWMI
This is a VBScript our company used to use - it uses WMI as Niklas B.'s solution does as well, so it will only work on XP SP3+. It uses the same provider as Windows Security Center (which doesn't always pick up every AV solution! However, does provide a lot of information on the AV solution.
Set objSWbemServices = GetObject("winmgmts:\\.\root\SecurityCenter")
Set colFirewall = objSWbemServices.ExecQuery("Select * From antivirusProduct",,48)
For Each objAntiVirusProduct In colFirewall
WScript.Echo "companyName: " & objAntiVirusProduct.companyName
WScript.Echo "displayName: " & objAntiVirusProduct.displayName
WScript.Echo "instanceGuid: " & objAntiVirusProduct.instanceGuid
WScript.Echo "onAccessScanningEnabled: " & objAntiVirusProduct.onAccessScanningEnabled
WScript.Echo "productUptoDate: " & objAntiVirusProduct.productUptoDate
WScript.Echo "versionNumber: " & objAntiVirusProduct.versionNumber
Next
Best of luck and happy coding!
I have this patch code which i downloaded from a web article (Calling Matlab from Java).
http://www.cs.virginia.edu/~whitehouse/matlab/JavaMatlab.html
But I donot know how to apply it in my windowsXp running computer.
What I'm trying to do is call Matlab script file from java. I have found the necessary source codes and every thing but this mater is holding be back.
Any help is highly appreciated. Thank you.
Here's the patch code.
Index: MatlabControl.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/java/net/tinyos/matlab/MatlabControl.java,v
retrieving revision 1.3
diff -u -r1.3 MatlabControl.java
--- MatlabControl.java 31 Mar 2004 18:43:50 -0000 1.3
+++ MatlabControl.java 16 Aug 2004 20:36:51 -0000
## -214,7 +214,8 ##
matlab.evalConsoleOutput(command);
}else{
- matlab.fevalConsoleOutput(command, args, 0, null);
+ // matlab.fevalConsoleOutput(command, args, 0, null);
+ matlab.fevalConsoleOutput(command, args);
}
} catch (Exception e) {
System.out.println(e.toString());
I'd download the standard UNIX patch tool and use:
patch -p0 <my_patch.diff
You need to apply that patch to the file MatlabControl.java. On Unix, you have the standard patch program to do that, but that ofcourse isn't normally present on Windows.
But looking at the patch file, it's very small and you could easily do the change by hand. Look at the patch file: The lines with a - in the left column must be removed. The lines with a + must be added.
So you must look in MatlabControl.java and remove this line:
matlab.fevalConsoleOutput(command, args, 0, null);
And add these lines:
// matlab.fevalConsoleOutput(command, args, 0, null);
matlab.fevalConsoleOutput(command, args);
In other words, it's a very small and simple change, you just have to remove the last two arguments to the method call to fevalConsoleOutput().
If you want the patch command (and lots of other Unix utilities) on Windows, you could download and install Cygwin.
If you use dev tools like Eclipse you can easily apply it as it is an option in the contextual menu (right click) go to Team - > Apply Patch. It should work.
This patch is so small, you can easily apply it by hand.
So simply open the file MatlabControl.java and change line 214 (the one prepended with -) to fit the lines prepended with +.
After that your code should look like:
else{
// matlab.fevalConsoleOutput(command, args, 0, null);
matlab.fevalConsoleOutput(command, args);
}
JMI (Java-to-Matlab Interface)'s Matlab class and its fevalConsoleOutput method are explained here: http://UndocumentedMatlab.com/blog/jmi-java-to-matlab-interface/
By Tortoise SVN, we can apply patch by following the below way. Click on Apply patch and browse the patch file.
Tortoise SVN