小编Cou*_*n22的帖子

在JEditorPane中设置默认字体

editorPane.setContentType("text/html");    
editorPane.setFont(new Font("Segoe UI", 0, 14));
editorPane.setText("Hello World");
Run Code Online (Sandbox Code Playgroud)

这不会改变文本的字体.我需要知道如何使用HTML Editor Kit设置JEditorPane的默认字体.

编辑:

在此输入图像描述

java fonts swing jeditorpane

12
推荐指数
3
解决办法
1万
查看次数

对于带数组的语句

我正在努力改变一些代码的长度.

我有这个:

    rects[1].setLocation(0, 0);
    rects[2].setLocation(100, 0);
    rects[3].setLocation(200, 0);
    rects[4].setLocation(300, 0);
    rects[5].setLocation(400, 0);
    rects[6].setLocation(500, 0);
    rects[7].setLocation(0, 50);
    rects[8].setLocation(100, 50);
    rects[9].setLocation(200, 50);
    rects[10].setLocation(300, 50);
    rects[11].setLocation(400, 50);
    rects[12].setLocation(500, 50);
    rects[13].setLocation(0, 100);
    rects[14].setLocation(100, 100);
    rects[15].setLocation(200, 100);
    rects[16].setLocation(300, 100);
    rects[17].setLocation(400, 100);
    rects[18].setLocation(500, 100);
    rects[19].setLocation(0, 150);
    rects[20].setLocation(100, 150);
    rects[21].setLocation(200, 150);
    rects[22].setLocation(300, 150);
    rects[23].setLocation(400, 150);
    rects[24].setLocation(500, 150);
Run Code Online (Sandbox Code Playgroud)

我把它改成了这个:

    for(int i = 1; i < 25; i++)
    {
        for(int j = 0; j < 550; j +=50)
        {
            for(int k = 0; k < 550; k +=50)
            { …
Run Code Online (Sandbox Code Playgroud)

java arrays for-loop

0
推荐指数
1
解决办法
126
查看次数

如何检测组件的碰撞?

如何检测组件的碰撞,特别是JLabel(或ImageIcons?)?我试过这个:

add(test1);
test1.setLocation(x, y);
add(test2);
test1.setLocation(x1, y1);
validate();

if(intersects(test1, test2))
{
    ehealth-=50;
}

public boolean intersects(JLabel testa, JLabel testb)
{
    boolean b3 = false;
    if(testa.contains(testb.getX(), testb.getY()))
    {
        b3 = true;
    }
    return b3;
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,它什么都不做!

我曾经使用过Rectangle,但它对我来说并不顺利.我正在考虑带边框的图像(使用paint.net)和移动图像,但我不知道如何获取ImageIcon的x或检测碰撞.我不知道如何检测标签的碰撞或增加位置.

我已经使用components/ImageIcons搜索了碰撞检测,但没有出现任何问题.我也搜索过获取ImageIcons的x.

java swing components jlabel collision-detection

0
推荐指数
1
解决办法
3049
查看次数

减少抽象类

我在这里有这个代码来创建一个键绑定:

KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
getInputMap(WHEN_IN_FOCUSED_WINDOW).put(k, k.toString());
getActionMap().put(k.toString(), new AbstractAction()
{ 
    public void actionPerformed(ActionEvent e)
    {
        //put action here
    }
});  
Run Code Online (Sandbox Code Playgroud)

问题是我的程序中有8个.其中每个都创建一个单独的类文件来保存抽象类.如果可能的话,我如何重写这个来限制创建的类的数量.(我已经搜索过这个,但是减少抽象类没有提供任何有用的东西)

java keyboard swing abstract-class key-bindings

-1
推荐指数
1
解决办法
78
查看次数