Android Studio 和基于 Swing 的应用程序的文本/UI 显示有问题。

huangapple go评论82阅读模式
英文:

Android Studio and Swing based apps text/ui is broken

问题

以下是您提供的内容的翻译:

这是我第一次下载 Android Studio,这是我在主菜单中获得的内容:

Android Studio 和基于 Swing 的应用程序的文本/UI 显示有问题。

基于 Swing 的应用程序的文本也存在相同的问题:

Android Studio 和基于 Swing 的应用程序的文本/UI 显示有问题。

Swing 应用程序的代码:

public class Base {
	private static JFrame JF;
	private static Map<String,JButton> Buttons = new HashMap<String,JButton>();
	
	public static void init(int x, int y) {
		JF = new JFrame();
		JF.setSize(x, y);
		JF.setLayout(null);
		JF.setVisible(true);
	}
	public static void CreateButton(String Bname,String BText,int posx, int posy, int sizex, int sizey) {
		final JButton Button = new JButton(BText);
		Button.setBounds(posx, posy, sizex, sizey);
		JF.add(Button);
		Buttons.put(Bname, Button);
	}
	public static void SetButtonEvent(EventActionType EType,String ButtonName) {
		if(EType == EventActionType.CLICKCOUNTER) {
			final JButton Button = Buttons.get(ButtonName);
			final JLabel Label = new JLabel("0");
			JF.add(Label);
			Label.setBounds(Button.getBounds().x,Button.getBounds().y + 50, 100, 100);
			Button.addActionListener(new ActionListener() {
				int Counter = 0;
				public void actionPerformed(ActionEvent e) {
					Counter++;
					Label.setText(String.valueOf(Counter));
				}
			});
		}
	}
}

主类:

public class Main extends Base {
	public static void main(String args[]) {
		init(400,500);
		CreateButton("Button_1","ClickMe",130,100,100, 40);
		SetButtonEvent(EventActionType.CLICKCOUNTER,"Button_1");
	}
}

GPU:Nvidia 1650

CPU:Intel core i5 9600

英文:

This is my first time downloading Android Studio and this what I get in the main menu:

Android Studio 和基于 Swing 的应用程序的文本/UI 显示有问题。

Swing based apps have the same problem with the text:

Android Studio 和基于 Swing 的应用程序的文本/UI 显示有问题。

The code for the swing app:

public class Base {
	private static JFrame JF;
	private static Map<String,JButton> Buttons = new HashMap<String,JButton>();
	
	public static void init(int x, int y) {
		JF = new JFrame();
		JF.setSize(x, y);
		JF.setLayout(null);
		JF.setVisible(true);
	}
	public static void CreateButton(String Bname,String BText,int posx, int posy, int sizex, int sizey) {
		final JButton Button = new JButton(BText);
		Button.setBounds(posx, posy, sizex, sizey);
		JF.add(Button);
		Buttons.put(Bname, Button);
	}
	public static void SetButtonEvent(EventActionType EType,String ButtonName) {
		if(EType == EventActionType.CLICKCOUNTER) {
			final JButton Button = Buttons.get(ButtonName);
			final JLabel Label = new JLabel("0");
			JF.add(Label);
			Label.setBounds(Button.getBounds().x,Button.getBounds().y + 50, 100, 100);
			Button.addActionListener(new ActionListener() {
				int Counter = 0;
				public void actionPerformed(ActionEvent e) {
					Counter++;
					Label.setText(String.valueOf(Counter));
				}
			});
		}
	}
}

The main Class:

public class Main extends Base {
	public static void main(String args[]) {
		init(400,500);
		CreateButton("Button_1","ClickMe",130,100,100, 40);
		SetButtonEvent(EventActionType.CLICKCOUNTER,"Button_1");
	}
}

GPU: Nvidia 1650

CPU: Intel core i5 9600

答案1

得分: 0

-- Android Studio 解决方案 --

为什么会出现这个问题?

我认为这是因为您正在使用的字体不受支持。要将其更改为受支持的字体,请按照以下步骤操作:

  1. 创建一个新的文本文件。
  2. 打开它并粘贴以下代码:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Segoe UI (TrueType)"=""
"Segoe UI Bold (TrueType)"=""
"Segoe UI Bold Italic (TrueType)"=""
"Segoe UI Italic (TrueType)"=""
"Segoe UI Light (TrueType)"=""
"Segoe UI Semibold (TrueType)"=""
"Segoe UI Symbol (TrueType)"=""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"Segoe UI"="Verdana"
  1. 转到文件,点击 "另存为"。
  2. 将其命名为 "font.reg",然后点击下拉菜单并选择 "所有文件",最后点击保存。
  3. 在运行文件之前,请检查代码,因为如果代码出错,可能会损坏您的计算机。
  4. 运行该文件并重新启动您的计算机。

这是对我有效的方法,希望对您也有用。

祝您有美好的一天/夜晚!

再见

英文:

-- android studio solution --

why is this problem occurring?

i think it is because the font your using is not supported, to change it to a supported one, follow these steps:

  1. Create a new text file
  2. open it and paste in this code
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
"Segoe UI (TrueType)"=""
"Segoe UI Bold (TrueType)"=""
"Segoe UI Bold Italic (TrueType)"=""
"Segoe UI Italic (TrueType)"=""
"Segoe UI Light (TrueType)"=""
"Segoe UI Semibold (TrueType)"=""
"Segoe UI Symbol (TrueType)"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
"Segoe UI"="Verdana"
  1. go to file, and click "save as"
  2. name it "font.reg" and click on the drop down and select "all files" and then click save
  3. before you run the file check the code because this can potentially ruin your computer if you miss up the code
  4. run the file and restart you computer

now this is the method that worked for me hopefully it will work for you.

Have a good day/night

Bye

huangapple
  • 本文由 发表于 2020年8月29日 19:23:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63646402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定