有几次我因为建议使用以下方法而受到批评:
在Swing组件上.当我想在显示的组件之间定义比例时,我没有看到任何替代它们的用法.我被告知这个:
对于布局,答案总是相同的:使用合适的LayoutManager
我在网上搜索了一下,但我没有找到任何关于这个主题的综合分析.所以我有以下问题:
我相信我们所有人都在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) 我是二年级学生,我正在研究我的OOP项目(计算器).我已经完成了数字按钮和运算符的功能.现在我正处于重新安排按钮的阶段.首先,我只是将按钮大小设置为(50,50),它工作正常,其标签仍然可见,但当我决定将其缩小(30,30)时,其标签变为"..."而不是.
这是照片:

继承我的代码:
lblEdit.setBounds(-138,-5,180,50);
lblView.setBounds(-90,-5,180,50);
lblHelp.setBounds(-40,-5,180,50);
txt.setBounds(15,35,250,30); // text pane
txt2.setBounds(0,330,100,20);
blank.setBounds(15,80,30,30); // this is just an extra button, no use at all, OK? :D
btnMC.setBounds(15,115,30,30);
btnMR.setBounds(15,150,30,30);
btnMS.setBounds(15,185,30,30);
btnMp.setBounds(15,220,30,30);
Run Code Online (Sandbox Code Playgroud) java user-interface swing layout-manager null-layout-manager