所以我有一个 JScrollPane,我需要滚动(仅垂直)通过居中的自动换行文本。文本后面应该是静态的、不可滚动的部分透明图像。
我的第一种方法是将图像添加到 JScrollPane 中的 JTextPane。由于强制图像从其存在的位置滚动而失败。
我的第二种方法是使 JTextPane 的背景透明并在 JLabel 上显示 JTextPane 后面的图像。由于 JTextPane 的背景无法在 JScrollPane 中透明,因此失败。- 现在我可以让它透明,但它会留下损坏、颜色错误和错位的文本以及随机出现在 JTextPane 上的滚动条。
我的第三种方法是使用 JTextArea 代替并在其后面显示图像。由于 JTextArea 无法将文本居中,这失败了。
我的第四种方法是使用 JLabel 来显示文本。由于 JLabel 无法自动换行,这失败了。尽管有些人似乎对此进行了 html 修复,但没有一个有效,因为它们都包裹在不正确的位置。
所以我不确定接下来应该尝试什么,任何帮助表示赞赏。
我正在尝试制作一个程序,查看用户输入的字母是否在字符串“ hello”中,如果是,请打印该字符串在字符串中以及字符串在字符串中的位置。错误是“二进制运算符的错误操作数类型”
String str = "hello", guess;
int testing = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a letter: ");
guess = scan.nextLine(); // Enters a letter
// finds the letter in the string
while (str.charAt(testing) != guess && testing != 6) {
testing++; // Continues loop
}
//prints where letter is if it is in the string
if (str.charAt(testing) == guess)
System.out.println("The letter is at "+testing);
else
System.out.println("Could not find that letter.");
Run Code Online (Sandbox Code Playgroud)