如何为JavaFX TextField文本启用抗锯齿功能?

时间:2019-04-09 02:46:54

标签: java javafx

我有一个TextField和一个Text对象。两者都使用完全相同的字体, 但是对于Text对象,有一种可以用来平滑字体的方法:public class B_Activity extends AppCompatActivity{ .... Camera camera; FrameLayout appCamera; CameraSurfaceAdapter cameraAdapter; Button btnCapture; TextView btnFinish; ArrayList<byte[]> byteArray; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_accident_camera); ..... appCamera = findViewById(R.id.appCamera); if (camera == null) { camera = Camera.open(); } cameraAdapter = new CameraSurfaceAdapter(getApplicationContext(), camera); appCamera.addView(cameraAdapter); // take picture byteArray = new ArrayList<byte[]>(); btnCapture = findViewById(R.id.btnCapture); btnCapture.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { takePicture(); } }); btnFinish = findViewById(R.id.btnFinish); btnFinish.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(byteArray != null){ Intent dataIntent = new Intent(); dataIntent.putExtra("array_size", byteArray.size()); for(int i = 0; i<byteArray.size() ; i++){ dataIntent.putExtra("byte_array" + i, byteArray.get(i)); } setResult(RESULT_OK, dataIntent); finish(); } }); } private void takePicture() { if (camera != null) { camera.takePicture(null, null, mPictureCallback); } else { } } Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { byteArray.add(data); camera.startPreview(); savePhoto(data); } }; ....... @Override public void onBackPressed() { btnFinish.performClick(); } @Override public void onDestroy() { super.onDestroy(); camera.stopPreview(); camera.release(); camera = null; } 。但是,TextField不存在这种方法。

正如Shaw所指出的,默认情况下,Text对象使字体平滑,但是TextField并非如此。

不幸的是,如下面的屏幕截图所示,这种区别很明显:

enter image description here

顶部是TextField,底部是具有平滑效果的Text。那么如何使TextField的字体平滑?

感谢您的帮助,谢谢!

1 个答案:

答案 0 :(得分:1)

我终于能够解决这个问题!使用Scene Builder的CSS分析器,我能够在-fx-font-smoothing-type下找到一个名为.text-field .text的属性。通过将值更改为gray,TextField中的文本将变得平滑!

Here's an updated screenshot.