"Learning gives Creativity,Creativity leads to Thinking, Thinking provides Knowledge, Knowledge makes you Great"
Friday, 25 July 2014
Wednesday, 23 July 2014
Tuesday, 22 July 2014
JavaFX: Removing child from a Group causes Exception
Free
You can't directly modify a List while you're iterating though it. The iterator gets confused.
Do
Do
List<Node> nodesToRemove = new ArrayList<>();
for(Node node : g.getChildren()){
if(node instanceof Text){
nodesToRemove.add(node);
}
}
g.getChildren().removeAll(nodesToRemove);
or (I think):for (Iterator<Node> iterator = g.getChildren().iterator(); iterator.hasNext();) {
if (iterator.next() instanceof Text) {
iterator.remove();
}
}
or, in Java8,g.getChildren().removeAll( g.getChildren().stream()
.filter(node -> node instanceof Text)
.collect(Collectors.toList()));
Wednesday, 16 July 2014
JavaFx Group
@DefaultProperty(value="children")
public class Group
extends Parent
- A
Group
node contains an ObservableList of children that are rendered in order whenever this node is rendered. AGroup
will take on the collective bounds of its children and is not directly resizable.
- Any transform, effect, or state applied to a
Group
will be applied to all children of that group. Such transforms and effects will NOT be included in this Group's layout bounds, however if transforms and effects are set directly on children of this Group, those will be included in this Group's layout bounds.
- By default, a
Group
will "auto-size" its managed resizable children to their preferred sizes during the layout pass to ensure that Regions and Controls are sized properly as their state changes. If an application needs to disable this auto-sizing behavior, then it should setautoSizeChildren
tofalse
and understand that if the preferred size of the children change, they will not automatically resize (so buyer beware!).
- Group Example:
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import java.lang.Math;
Group g = new Group();
for (int i = 0; i < 5; i++) {
Rectangle r = new Rectangle();
r.setY(i * 20);
r.setWidth(100);
r.setHeight(10);
r.setFill(Color.RED);
g.getChildren().add(r);
}
Wednesday, 9 July 2014
How to get IP address in Java using InetAddress
An Internet Protocol address (IP address) is a
numerical label assigned to each device (e.g., computer, printer)
participating in a computer network that uses the Internet Protocol for
communication. The designers of the Internet Protocol defined an IPv4
address as a 32-bit number.
In this tutorial we are going to see
how can you get the IP Address that is assigned to your own machine
inside your local network and the IP Addresses assigned to specific
Domain Names(e.g. www.google.com…).
To do that we are going to use
InetAddress
.To be more specific we are going to use:getLocalHost().getHostAddress()
method ofInetAddress
to get the IP Address of our machine in our local networkgetByName()
method ofInetAddress
to get the IP Address of a specific Domain NamegetAllByName()
method ofInetAddress
to get all the IP Address of a specific Domain Name.
Tuesday, 8 July 2014
How to print all the Java system properties
The other day, when I was trying to compile all the Tame Swing examples,
I had a problem running one of the examples. The problem was that I was
running the example in Eclipse, and I was getting an error message
showing the Eclipse (the JVM really) couldn't find the icon image files.
I thought I had everything configured properly, but still I
kept getting the same error message. Finally I decided to look at my
Java system properties and see what my build path really looked like. I
couldn't think of the right Java property to show the build path, so
instead of trying to print just the one Java property, I decided to
print all the Java properties, then dig through them manually. You print
Java system properties with the
System.getProperties()
method.
Here's the code I used to print all the Java system properties:
Properties p = System.getProperties(); Enumeration keys = p.keys(); while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); String value = (String)p.get(key); System.out.println(key + ": " + value); } |
And here's the output from that section of code:
java.runtime.name: Java(TM) 2 Runtime Environment, Standard Edition sun.boot.library.path: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries java.vm.version: 1.5.0_07-87 awt.nativeDoubleBuffering: true gopherProxySet: false java.vm.vendor: "Apple Computer, Inc." java.vendor.url: http://apple.com/ path.separator: : java.vm.name: Java HotSpot(TM) Client VM file.encoding.pkg: sun.io user.country: US sun.os.patch.level: unknown java.vm.specification.name: Java Virtual Machine Specification user.dir: /Users/al/DD/Projects/TameSwing java.runtime.version: 1.5.0_07-164 java.awt.graphicsenv: apple.awt.CGraphicsEnvironment java.endorsed.dirs: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/endorsed os.arch: i386 java.io.tmpdir: /tmp line.separator: java.vm.specification.vendor: Sun Microsystems Inc. os.name: Mac OS X sun.jnu.encoding: MacRoman java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java java.specification.name: Java Platform API Specification java.class.version: 49.0 sun.management.compiler: HotSpot Client Compiler os.version: 10.4.10 user.home: /Users/al user.timezone: java.awt.printerjob: apple.awt.CPrinterJob file.encoding: MacRoman java.specification.version: 1.5 java.class.path: /Users/al/DD/Projects/TameSwing/bin:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/.compatibility/14compatibility.jar user.name: al apple.awt.graphics.UseQuartz: true java.vm.specification.version: 1.0 java.home: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home sun.arch.data.model: 32 user.language: en java.specification.vendor: Sun Microsystems Inc. awt.toolkit: apple.awt.CToolkit java.vm.info: mixed mode, sharing java.version: 1.5.0_07 java.ext.dirs: /Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/ext sun.boot.class.path: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/charsets.jar java.vendor: Apple Computer, Inc. file.separator: / java.vendor.url.bug: http://developer.apple.com/java/ sun.io.unicode.encoding: UnicodeLittle sun.cpu.endian: little mrj.version: 1040.1.5.0_07-164 sun.awt.exception.handler: apple.awt.CToolkit$EventQueueExceptionHandler sun.cpu.isalist:
Subscribe to:
Posts (Atom)