如何在javaFX中实现抗锯齿?我已经应用了一些技巧......但它没有用

时间:2015-05-25 12:24:55

标签: javafx-2 javafx-8

在阅读完问题之后,看起来我已经问过已经问过的问题,但是相信我已经尝试过可能的解决方案,但是我没有得到所需的输出....

首先我要实现的目标是什么?

enter image description here

为了实现AntiAliasing,我尝试了一些像

这样的方法
  1. 新场景(,SceneAntialiasing.BALANCED);
  2. 形状[对象] .setSmooth(真);
  3. System.setProperty(" prism.lcdtext"," false");从链接 How to force anti-aliasing in JavaFX fonts?
  4. 我也尝试过使用SubScene,但这有点不合适......
  5. 但上述解决方案都不适合我...所以现在,我发布了 SSCVE ......

    请帮帮我...

    提前致谢...

    SSCVE

    the CreateScene method in UI class which  extends JFXPanel looks like ....  
    
    private Scene createScene() 
    {  
    
        Group rootNode = new Group();
        //System.setProperty("prism.lcdtext", "false");
        double StrokeWidth = 1.0;
        double yPosition = 20.0;
        //textFontsize = textFontsize + 0.7 ;
    
        // straight Vertical Lines
    
                rootNode.getChildren().add(createLines(35.0, yPosition+20, 35.0, yPosition+150, StrokeWidth,"GREEN"));
                rootNode.getChildren().add(createLines(25.0, yPosition+20, 25, yPosition+150, StrokeWidth,"BLACK"));
                rootNode.getChildren().add(createLines(30.0, yPosition+20, 30, yPosition+150, StrokeWidth,"BLUE"));
    
                // straight horizontal lines
    
                rootNode.getChildren().add(createLines(80.0, yPosition+30, 240, yPosition+30, StrokeWidth,"RED"));
                rootNode.getChildren().add(createLines(80.0, yPosition+40, 240, yPosition+40, StrokeWidth,"GREEN"));
                rootNode.getChildren().add(createLines(80.0, yPosition+50, 240, yPosition+50, StrokeWidth,"BLACK"));
    
                // create slope lines 
    
                rootNode.getChildren().add(createLines(420.0, yPosition+20, 470, yPosition+150, StrokeWidth,"BLACK"));
                rootNode.getChildren().add(createLines(430.0, yPosition+20, 480, yPosition+150, StrokeWidth,"RED"));
                rootNode.getChildren().add(createLines(440.0, yPosition+20, 490, yPosition+150, StrokeWidth,"BLUE"));
                rootNode.getChildren().add(createLines(450.0, yPosition+20, 500, yPosition+150, StrokeWidth,"GREEN"));
    
                double textFontsize = 12.0;
                String fontColor = "RED";
    
                String font ="Arial";
                int count = 5;
                String newLine = null;
    
                if(count == 5)
                {
                    newLine = "\n\n\n\n\n";
                }
    
                rootNode.getChildren().add(createText(50,yPosition+230,font,textFontsize, newLine+"15352465 \n"
                        + "Circle is "+StrokeWidth+" . "+"Font name is "+font+" . Minimum visible font size is 0.7 ."
                        + "\n The Font size for text is "+textFontsize+". ",fontColor, StrokeWidth));
    
    
        ScrollPane scroll = new ScrollPane();
        scroll.setHbarPolicy(ScrollBarPolicy.ALWAYS);
        scroll.setVbarPolicy(ScrollBarPolicy.NEVER);
        scroll.setContent(rootNode);
    
        //iv.setClip(new Rectangle(0,20,250,200));
        Scene sc =  new  Scene(scroll, 500,500,false,SceneAntialiasing.BALANCED); 
        SceneAntialiasing value = sc.getAntiAliasing();
        return sc;
    }
    
    public Line createLines(double startX, double startY, double endX, double endY, double strokeWidth, String strokeColor)
    {
        Line line = new Line(startX-0.5, startY-0.5, endX-0.5, endY-0.5);   
        if(strokeColor.equals("BLUE"))
        {
            line.setStroke(javafx.scene.paint.Color.BLUE);
        }
        else if(strokeColor.equals("RED"))
        {
            line.setStroke(javafx.scene.paint.Color.RED);
        }
        else if(strokeColor.equals("GREEN"))
        {
            line.setStroke(javafx.scene.paint.Color.GREEN);
        }
        else if(strokeColor.equals("BLACK"))
        {
            line.setStroke(javafx.scene.paint.Color.BLACK);
        }
        line.setStrokeWidth(strokeWidth);
        //line.setSmooth(true);
        return line;
    }
    
    
    
    public Text createText(double xParam, double yParam, String fontType, double fontSize, String text, String strokeColor, double StrokeWidth)
    {
         Text txt = new Text(text);
         txt.setX(xParam);
         txt.setY(yParam);  
    
    
    
         if(fontType.equals("Comic Sans MS"))
         {
             txt.setFont(Font.font(fontType,FontWeight.BOLD, fontSize));
         }
         else
         {
             txt.setFont(Font.font(fontType, fontSize));
         }
    
         //txt.setStrokeWidth(StrokeWidth);
         if(strokeColor.equals("BLUE"))
            {
                txt.setFill(Color.BLUE);
            }
            else if(strokeColor.equals("RED"))
            {
                txt.setFill(javafx.scene.paint.Color.RED);
            }
            else if(strokeColor.equals("GREEN"))
            {
                txt.setFill(javafx.scene.paint.Color.GREEN);
            }
            else if(strokeColor.equals("BLACK"))
            {
                txt.setFill(javafx.scene.paint.Color.BLACK);
            }
            else if(strokeColor.equals("BROWN"))
            {
                txt.setFill(javafx.scene.paint.Color.BROWN);
            }
        // txt.setFontSmoothingType(FontSmoothingType.LCD);
        // txt.setStrokeType(StrokeType.INSIDE);
         return txt;
    }   
    

0 个答案:

没有答案