我相信我们所有人都在Facebook状态(或其他地方)看过省略号,然后点击"显示更多"并且只有另外两个字符左右.我猜这是因为懒惰的编程,因为肯定有一种理想的方法.
我将细长的字符[iIl1]称为"半字符",但是当它们几乎不隐藏任何字符时,这并不会使省略号看起来很傻.
有理想的方法吗?这是我的:
/**
* Return a string with a maximum length of <code>length</code> characters.
* If there are more than <code>length</code> characters, then string ends with an ellipsis ("...").
*
* @param text
* @param length
* @return
*/
public static String ellipsis(final String text, int length)
{
// The letters [iIl1] are slim enough to only count as half a character.
length += Math.ceil(text.replaceAll("[^iIl]", "").length() / 2.0d);
if (text.length() > length)
{
return text.substring(0, length - …Run Code Online (Sandbox Code Playgroud) 如果我创建不可调整大小的JFrame,并启用Windows Aero setLocation似乎没有正确考虑窗口边框.
在下面的代码中,我希望第二帧位于第一帧的右侧,而不是边框重叠.如果禁用Aero,或者我删除了setResizable对此的调用,则按预期完成.
import java.awt.Rectangle;
import javax.swing.JFrame;
public class FrameBorders {
public static void main(String[] args) {
JFrame frame1 = new JFrame("frame 1");
JFrame frame2 = new JFrame("frame 2");
frame1.setResizable(false);
frame2.setResizable(false);
frame1.setVisible(true);
Rectangle bounds = frame1.getBounds();
frame2.setLocation(bounds.x+bounds.width, bounds.y);
frame2.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么或这是一个错误?如何在没有重叠边框的情况下并排显示2个不可调整的对话框?
编辑:添加了截图(也将frame2更改为JDialog而不是JFrame)
Aero On:

Aero Off:

Aero On但可调整大小:
