检查大家乐棋牌文本的截断(Java,Swing)

最后编辑了

此示例大家乐棋牌了如何检查JComponent(或JComponent的子类)中大家乐棋牌的文本是否已被截断(例如,因为它比GUI控制的宽度宽)。

The is_truncated_swing() function compares the widget’s actual width (from its width property), with the number of pixels needed to display the entire text (returned by the requiredWidth() function), and calls Squish’ test.fail() function if the actual width is less than the required width.

def main():
    n = {"caption": "Backspace", "type": "javax.swing.JButton", "visible": True}
    o = waitForObject(n)
    msg = "Truncation check: Object: %s: Text: %s " % (n, o.text)
    if is_truncated_swing(o, o.text):
        test.fail(msg)
    else:
        test.passes(msg)

def is_truncated_swing(obj, text):
    font_metrics = obj.getFontMetrics(obj.font)
    return obj.width <= font_metrics.stringWidth(text)