有几次我因为建议使用以下方法而受到批评:
在Swing组件上.当我想在显示的组件之间定义比例时,我没有看到任何替代它们的用法.我被告知这个:
对于布局,答案总是相同的:使用合适的LayoutManager
我在网上搜索了一下,但我没有找到任何关于这个主题的综合分析.所以我有以下问题:
我有一个应用程序,它使用遍布文本和图标的自定义按钮.适用于Windows和Linux,但现在OSX用户抱怨.文本不会显示在Mac上,只是'...'.代码看起来很简单,但是当涉及到mac时我很无能为力.我怎样才能解决这个问题?
测试用例:
package example.swingx;
import example.utils.ResourceLoader;
import com.xduke.xlayouts.XTableLayout;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.event.ActionEvent;
public class SmallButton extends JButton {
private static ComponentUI ui = new SmallButtonUI();
public SmallButton() {
super();
/* final RepaintManager repaintManager = RepaintManager.currentManager(this);
repaintManager.setDoubleBufferingEnabled(false);
setDebugGraphicsOptions(DebugGraphics.FLASH_OPTION);*/
}
public SmallButton(AbstractAction action) {
super(action);
}
public SmallButton(String text) {
super(text);
}
public SmallButton(Icon icon) {
super(icon);
}
public void updateUI() {
setUI(ui);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel …Run Code Online (Sandbox Code Playgroud) 我正在为我的班级编写一个java应用程序.这是一个电话键盘.我快完成了.我只需要显示数字,我就不知道如何更改数字按钮的大小.到目前为止我尝试过的所有内容在编译时都会导致错误.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JApplet;
import javax.swing.JFrame;
import java.awt.event.*;
public class TelephoneKeypad extends javax.swing.JFrame
{
public TelephoneKeypad()
{
Panel pnlKeyPad = new Panel();
GridLayout gridLayout1 = new GridLayout();
Button btnZero = new Button();
Button btnOne = new Button();
Button btnTwo = new Button();
Button btnThree = new Button();
Button btnFour = new Button();
Button btnFive = new Button();
Button btnSix = new Button();
Button btnSeven = new Button();
Button btnEight = new …Run Code Online (Sandbox Code Playgroud) 在各种 Pluggable Look & Feel 实现中,Swing 文本字段在可编辑、不可编辑和禁用时是什么样子的?
下面是在 Windows 和 Apple OS X 上看到的 PLAF 的答案。我也非常感谢看到其他 PLAF 的外观(例如 *nix 上的 GTK)。