简体   繁体   English

在OS X上的swing应用中移动了文本

[英]Shifted text in swing app on OS X

I have a little java+swing app. 我有一个Java + Swing小应用程序。 Until now it worked OK, on OS X and on windows. 到目前为止,在OS X和Windows上都可以正常运行。

But recenly a user has noticed that on his OS X (version unknown yet, nor the java version) that all texts in the GUI are shifted up and cut (as you can see on the screenshot). 但是最近有一个用户注意到,在他的OS X(尚不知道版本,也不是Java版本)上,GUI中的所有文本都被上移和剪切了(如屏幕截图所示)。

wrong look http://b3.s3.quickshareit.com/picture1ac6aa.png 看错了http://b3.s3.quickshareit.com/picture1ac6aa.png

And HTML link is shifted down and cut. HTML链接被下移和剪切。 All those elements are JLabels. 所有这些元素都是JLabels。

This is how it should look like 这就是它的样子

ok look http://b1.s3.quickshareit.com/screenshot_45f5e29f947e59b81.png 好的,看http://b1.s3.quickshareit.com/screenshot_45f5e29f947e59b81.png

Any ideas/help? 有任何想法/帮助吗? Has anybody had this problem before? 有人遇到过这个问题吗? I have no clue where to start. 我不知道从哪里开始。 Thanks for any help 谢谢你的帮助

I googled "java jlabel crop/cut" etc. 我用Google搜索了“ java jlabel裁剪/剪切”等。

========== ==========

fragment of the code 代码片段

import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import System.DnDList;
import System.QSTWindow;
import System.configuration.Configuration;


public class Test extends JFrame
{
    private static final long serialVersionUID = 8698865819017225558L;

    public static void main(String[] args)
    {
        Test main = new Test();
        main.setVisible(true);
    }

    private JPanel down_panel;
    private JButton b_Preferences;
    private JButton b_AddFile;
    private JButton b_Send2;
    private JButton b_Cancel;
    private JButton b_Cancel2;
    private DnDList dndList;
    private JLabel filesToSendLabel;
    private JLabel browseFilesLabel;
    private JPanel selectedFilesPanel;
    private JPanel gPanel;    

    public Test()
    {
        this.setLayout(null);
        this.setBackground(new java.awt.Color(255, 255, 255)); // XXX move color to configuration class
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        this.setSize(360, 525); // whole window

        gPanel = new JPanel();
        gPanel.setLayout(null);
        gPanel.setBackground(new java.awt.Color(255, 255, 255));
        gPanel.setBounds(0, 0, 365, 525); // whole window panel


        selectedFilesPanel = new JPanel();
        selectedFilesPanel.setLayout(null);
        selectedFilesPanel.setBounds(0, 333, 440, 122);
        selectedFilesPanel.setBackground(new java.awt.Color(255, 255, 255));

        down_panel = new JPanel(); // panel with info button and upload button
        down_panel.setLayout(null);
        down_panel.setBackground(new java.awt.Color(255, 255, 255));
        down_panel.setBounds(0, 430, 365, 80);

        // icon taken from http://en.wikibooks.org/wiki/Image:Information_icon.svg
        b_Preferences = new JButton("PREF");
        b_Preferences.setFocusPainted(false);
        b_Preferences.setToolTipText("Settings");
        b_Preferences.setBackground(Configuration.getBACKGROUND_COLOR());
        b_Preferences.setBounds(11, 25, 32, 32);
        b_Preferences.setMargin(new Insets(0, 0, 0, 0));
        b_Preferences.setBorderPainted(false);

        b_AddFile = new JButton("Browse");
        b_Send2 = new JButton(new ImageIcon(QSTWindow.class.getResource("upload.png")));
        b_Cancel = new JButton("Cancel");
        b_Cancel2 = new JButton("Cancel");

        dndList = new DnDList(selectedFilesPanel, 8, 10, 364, 97, this);

        filesToSendLabel = new JLabel("Media to send");
        filesToSendLabel.setFont(Configuration.getDEFAULT_LABEL_FONT());
        filesToSendLabel.setBounds(10, 325, 150, 14);
        browseFilesLabel = new JLabel("<HTML><U>Browse</U></HTML>");
        browseFilesLabel.setForeground(Configuration.getLINK_COLOR());
        browseFilesLabel.setFont(Configuration.getLINK_FONT());
        browseFilesLabel.setBounds(90, 325, 50, 14);

        b_Send2.setBounds(272, 25, 72, 26);
        b_Send2.setMargin(new Insets(3, 0, 3, 0));

        down_panel.add(b_Preferences);
        down_panel.add(b_Send2);

        gPanel.add(filesToSendLabel);
        gPanel.add(browseFilesLabel);
        gPanel.add(selectedFilesPanel);
        gPanel.add(down_panel);

        this.add(gPanel);
        this.setResizable(false);
    }
}

Sorry that this example is not compillable (you'd need half of the app), but shows the problematic elements. 抱歉,此示例不可编译(您需要使用应用程序的一半),但显示了有问题的元素。

I was thinking that maybe the problem has something to do with the Fonts installed in the system. 我当时在想问题可能与系统中安装的字体有关。

Can you set the text to some known Font that you're 100% sure it's going to be installed in the system? 您是否可以将文本设置为某种可以100%确定将在系统中安装的已知字体?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM