How to make JavaFX Applications non-blurry on Retina Display - scala

A JavaFX application appears blurry on the MacBook Pro Retina screen. Is there a way to display the application sharp? In a blog post/comment was mentioned that this is the case currently: http://fxexperience.com/2012/11/retina-display-macbook-pro/
This is the example fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<VBox xmlns:fx="http://javafx.com/fxml">
<MenuBar>
<Menu text="File">
<items>
<MenuItem text="Exit"/>
</items>
</Menu>
</MenuBar>
</VBox>
Example code:
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Scene
import javafx.scene.layout.VBox
import javafx.scene.paint.Color
import javafx.stage.Stage
object CreateFX extends App {
override def main(args: Array[String]) = {
println("CreateFX starting up...")
Application.launch(classOf[CreateFX], args: _*)
}
}
class CreateFX extends Application {
def start(stage: Stage): Unit = {
println("start "+stage)
stage.setTitle("CreateFX")
val root: VBox = FXMLLoader.load(getClass().getResource("MainScreenVBox.fxml"))//new VBox
val scene = new Scene(root, 800, 600)
scene.setFill(Color.GREEN)
stage.setScene(scene)
stage.show()
}
}
Outcome:
Java Version: 1.7.0_21

In the same article in the commentary Richard Blair stated that this was fixed in the latest JavaFX version (available in the EAP of Java 8, downloadable here)

Related

JavaFX RadioButton setSelected() not working

I'm creating a JavaFX FXML application and haven't been able to use the setSelected() method to set one of two radio buttons by default in a toggle group. The toggle group is functioning normally, so it appears the radio button variables are being set correctly. However, radio1 is not selected as expected.
Following are the relevant sections of my application.
System Information
Product Version: NetBeans IDE 8.1 (Build 201510222201)
Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1
Java: 1.8.0_171; Java HotSpot(TM) 64-Bit Server VM 25.171-b11
Runtime: Java(TM) SE Runtime Environment 1.8.0_171-b11
System: Mac OS X version 10.13.4 running on x86_64; UTF-8; en_US (nb)
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="400.0"
xmlns="http://javafx.com/javafx/8.0.141"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="inventory.view.AddPartController">
<fx:define>
<ToggleGroup fx:id="toggleGroup" />
</fx:define>
<children>
<RadioButton fx:id="radio1" mnemonicParsing="false"
onAction="#handleRadio1" prefHeight="30.0" prefWidth="100.0"
text="radio1" toggleGroup="$toggleGroup"
AnchorPane.rightAnchor="125.0" AnchorPane.topAnchor="25.0" />
<RadioButton fx:id="radio2" mnemonicParsing="false"
onAction="#handleRadio2" prefHeight="30.0" prefWidth="100.0"
text="radio2" toggleGroup="$toggleGroup"
AnchorPane.rightAnchor="25.0" AnchorPane.topAnchor="25.0" />
</children>
</AnchorPane>
Controller
package inventory.view;
import inventory.InventorySystem;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
public class AddPartController {
#FXML
private ToggleGroup toggleGroup;
#FXML
private RadioButton radio1;
#FXML
private RadioButton radio2;
#FXML
private void initialize() {
toggleGroup = new ToggleGroup();
radio1 = new RadioButton();
radio1.setToggleGroup(toggleGroup);
radio1.setSelected(true);
radio2 = new RadioButton();
radio2.setToggleGroup(toggleGroup);
}
}
Where am I going wrong?
You are reinitializing the radio button. The FXML will inject the reference, you are then overriding it. You also define the toggle group in your FXML - so you don't need that either.
Change your code to look like this:
#FXML
private void initialize() {
radio1.setSelected(true);
}
Don't initialize the buttons again . These lines would be enough.
#FXML
private void initialize() {
radio1.setToggleGroup(toggleGroup);
radio1.setSelected(true);
radio2.setToggleGroup(toggleGroup);
}

#Before Suite and #BeforeTest methods are not called if groups are executed in TestNG

Below is my XML file and Demo Class. Precondition() method will run before demo1() method and postCondition() method will run after demo1() method. Same process is for demo2(). But when i run the code, BeforeSuite and BeforeTest Methods are not Called. Why.? How to call them ?
Output :
Before Method is executing
DEMO -1
After Method is executing
Before Method is executing
DEMO 2
After Method is executing
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name = "Hey"></include>
</run>
</groups>
<classes>
<class name="practicepackage.Demo"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
package practicepackage;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Demo {
#BeforeSuite
public void beforeSuite(){
System.out.println("Before Suite method is being launched");
}
#BeforeTest
public void beforeTest(){
System.out.println("Before Test Method is being luanched");
}
#BeforeMethod(groups = {"Hey"})
public void PreCondition(){
System.out.println("Before Method is executing");
}
#Test (groups = {"Hey"})
public void demo1(){
System.out.println("DEMO -1 ");
}
#Test(groups = {"Hey"})
public void demo2(){
System.out.println("DEMO 2");
}
#AfterMethod(groups = {"Hey"})
public void postCondition(){
System.out.println("After Method is executing");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name = "Hey"></include>
</run>
</groups>
<classes>
<class name="practicepackage.Demo"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
In order to ensure that #BeforeSuite and #BeforeTest are executed all the time, please enable the attribute alwaysRun=true for these annotations.
This is required because when you run through groups, these configuration methods wont be selected by TestNG until and unless they are part of the group which you selected.
Group selection in TestNG can be visualised as a sort of filtering mechanism in TestNG that lets you tell TestNG the criteria for filtering, when it decides which tests to run.

Proper way to import custom UI into scene builder?

I am trying to build an UI with custom control. But having trouble to make the scene builder wo work properly with the custom part.
My custom control:
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="800.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
...other code
</children>
</fx:root>
Room.fxml, which use the custom class:
...other code
<?import ag.ctrl.*?>
<?scenebuilder-classpath-element ../../target/classes/ag/ctrl?>
...other code
<BorderPane prefHeight="200.0" prefWidth="200.0"
BorderPane.alignment="CENTER">
<top>
<TeamArea />
</top>
</BorderPane>
Controller of the custom ui:
package ag.ctrl;
...
public class TeamArea extends AnchorPane {
...
public TeamArea() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(
"/ui/TeamArea.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
...
}
and all those files' path:
TeamArea.fxml: /resource/ui/TeamArea.fxml
Room.fxml: /resource/ui/Room.fxml
TeamArea.class: /target/classes/ag/ctrl/TeamArea.class
I try many different approach before.End up with scene builder's class not found error or others.
Currently I am having an unresolved class error at the TeamArea Node in scene builder.
Some stupid error must in somewhere...
Could any one help?
I think you link to the wrong classpath.
Take a look at this thread
Hope that solves your problem.
Your classpath needs to be:
<?scenebuilder-classpath-element ../../target/classes?>
However, I'm facing the same problem and it doesn't work that way either. Please drop me a comment if you got it working

Magento: error for custom module (Class not found in Layout.php)

I tried to create a new custom module (block) in Magento which will show other products from manufacturer on product detail page. When I load product detail page I get:
Fatal error: Class 'AimIT_ManufacturerBlock_Block_Manufacturerblock' not found in ..\app\code\core\Mage\Core\Model\Layout.php on line 491
I have created:
1)\app\etc\modules\AimIT_ManufacturerBlock.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<AimIT_ManufacturerBlock>
<!-- Whether our module is active: true or false -->
<active>true</active>
<!-- Which code pool to use: core, community or local -->
<codePool>local</codePool>
</AimIT_ManufacturerBlock>
</modules>
</config>
2) \app\code\local\AimIT\ManufacturerBlock\etc\config.xml
<?xml version="1.0"?>
<config>
<global>
<blocks>
<aimitmanufacturerblock>
<class>AimIT_ManufacturerBlock_Block</class>
</aimitmanufacturerblock>
</blocks>
</global>
</config>
3) \app\code\local\AimIT\ManufacturerBlock\Block\Manufacturerblock.php
<?php
class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template
{
public function getManufacturerProducts($manufacturer)
{
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('manufacturer',$manufacturer);
$collection->addAttributeToSelect('manufacturer');
return $collection;
}
}
?>
4)\app\design\frontend\default\respond\template\aimit\manufacturerblock\manufacturerblock.phtml
<?php $_products = $this->getManufacturerProducts('cukrarna-u-vanku') ?>
<?php print_r($_products); ?>
5) in catalog\product\view.phtml I have placed this code:
<?php echo $this->getLayout()->createBlock('aimitmanufacturerblock/manufacturerblock')->setTemplate('aimitmanufacturerblock/manufacturerblock.phtml')->toHtml(); ?>
What did I omit while creating the module?
When translating 'aimitmanufacturerblock/manufacturerblock' into a class name Magento generates AimIT_ManufacturerBlock_Block_Manufacturerblock and can't find a class under such name because your block's class name is actually 'AimIT_ManufacturerBlock_Block_ManufacturerBlock' - which is wrongly cased.
Rename your class into
class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template
{
Rename your class file ManufacturerBlock.php into Manufacturerblock.php

How to import a custom class into mxml file in Flex? (Actionscript 3)

i need to import my own class to the mxml file, but allways comes an error that classes cant be nested. I dont know how to use my classes (example: NetConn.as). Can you help me?
<!--language:actionscript3>
<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.eazyRadioHomeView">
<fx:Style source="eazyRadio.css"/>
<fx:Script>
<![CDATA[
include "NetConn.as";
import myNetConn;
var easy=new NetConnectionEx();
]]>
</fx:Script>
<fx:Declarations>
<!-- Platzieren Sie nichtvisuelle Elemente (z. B. Dienste, Wertobjekte) hier -->
</fx:Declarations>
</s:ViewNavigatorApplication>
-->
You need
import com.yournamespace.NetConn;
instead of
include "NetConn.as"