- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我制作挥杆计算器并设置按钮时,每个按钮间隔均匀,但最后添加的按钮总是占据整个屏幕,这是设置按钮的方法;
private void setupRelations() {
window.setJMenuBar(menuBar);
window.setLayout(new BorderLayout());
window.add(inputPanel, BorderLayout.NORTH);
window.add(buttonsPanel);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
copyResult.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
StringSelection selection = new StringSelection(input.getText());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, null);
}
});
pasteInput.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String result = "";
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
boolean hasTransferableText = (contents != null) &&
contents.isDataFlavorSupported(DataFlavor.stringFlavor);
if (hasTransferableText) {
try {
result = (String)contents.getTransferData(DataFlavor.stringFlavor);
} catch (UnsupportedFlavorException ex){
System.out.println(ex);
ex.printStackTrace();
} catch (IOException ex) {
System.out.println(ex);
ex.printStackTrace();
}
}
input.setText(result);
}
});
windowOperations.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
specialOperations.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
file.add(copyResult);
file.add(pasteInput);
file.add(exit);
windows.add(windowOperations);
windows.add(specialOperations);
menuBar.add(file);
menuBar.add(windows);
inputPanel.setLayout(new BorderLayout());
input.setEditable(false);
input.setText("sss");
input.setHorizontalAlignment(JTextField.CENTER);
input.setFont(font);
inputPanel.add(input);
buttonsPanel.setLayout(new BorderLayout());
buttonsPanel.setBounds(window.getX() + (75 - 65), window.getY() + 13, 500, 500);
int sLength = 65;
int padding = 75;
for(int i = 0; i < buttonNames[i].length; i++) {
for(int j = 0; j < buttonNames.length; j++) {
JButton button = new JButton(buttonNames[j][i]);
button.setBounds(buttonsPanel.getX() + i * padding,
buttonsPanel.getY() + j * padding, sLength, sLength);
button.addActionListener(getActionListener(i, j));
buttonsPanel.add(button);
}
}
}
getActionListener方法仅用于获取按钮对应的操作,有人可以帮助我吗?
最佳答案
您的布局错误。在 BorderLayout 中,当您添加组件而不指定北、南、东或西时,会将组件添加到中间,并且该组件会占据那里的所有空间。
通常对于计算器,您需要一个 GridLayout:它将可用空间划分为行和列中大小相等的区域,通常正是您想要的计算器中的数字。
要将它们放入 BorderLayout(假设您希望在数字按钮的一侧或另一侧放置其他内容),请在面板上设置 GridLayout,将按钮放入其中,然后将该面板放入 (中间的)(带有)BorderLayout 的组件。
关于java - 我正在制作一个带有 swing 的计算器,但按钮都搞乱了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40909253/
所以我昨天尝试开始使用 std::initializer_list 但这并不是一个巨大的成功。这是我最后的尝试之一: #include #include struct XmlState
我读到,JVM gc 在找到无法访问的对象后,会运行该对象的 Finalize() 方法。然后它检查该对象是否仍然无法访问,如果不是则删除它。所以我写了一个终结,使它的对象的引用再次可用: publi
所以,我收到了一些文件,其中包含一堆这样的东西 var time=0;//ÓÎϷʱ¼ä 很明显,评论对应的东西,我想看,但是乱七八糟的,我不知道为什么。 1) 我怎么读这个 2)如何避免 最佳答案
在阅读之前,请注意我是 jquery、html 和 css 方面的初学者。 在将 jquery 安装到我的网站之前,我将页眉和页脚固定在固定位置,以便它们粘在浏览器的顶部和底部。当我安装jquery时
我用Minamaze1.1.2主题免费添加了一个网站。在更改 CSS 代码时,我以某种方式更改了 slider 图片的尺寸。现在左侧与右侧不成比例。 在网址中可以看到: http://springlo
我已经创建了一个下拉框阴影和悬停图像的示例,除了通常的问题 internet explerror 之外,它似乎工作正常。你可以在这里查看 fiddle : www.jsfiddle.net/kcD6j
我正在按照 Spring 教程开始使用 JPA,并且我有一个带有 user 表的基本 mysql 数据库。 我已按如下方式设置User.java: package com.test.models; i
假设我有三个表 - 用户、服务器和付款。每个用户可以拥有多个服务器,每个服务器可以进行多次支付。假设我想查找最近的付款并获取有关这些付款所附加的服务器/客户的信息。这是一个可以执行此操作的查询: SE
我为我的购物车、注册、登录和联系表启用了 SSL。当启用 SSL 时,jquery 被禁用。我看到谷歌也有使用 https 导入的 jquery。 这是页面 https://americanbookc
这是一个标准任务:在应用程序的共享首选项中存储一些值,以便以后能够检索它。但是人们会发现有 3 个函数可以在其中存储一个值: //1. public static SharedPreferences
我正在尝试使用 SLRequest iOS API 获取 facebook 数据,这似乎工作正常 - NSDictionary *parameters = @{}; NSURL *feedURL =
好的,所以我用 jQuery 实现了整个页面的隐藏/淡入效果。一切都很顺利,直到我意识到delay() + fadeIn()导致我的 Hashtag Links 以顶部的滚动位置加载,而不是 #my_
因此,在我将 DNS 移至 Godaddy 之前,该站点在 Internet Explorer 中运行良好。这是网站.. http://csdassociates.com/ ...关于为什么这不再正确
由于某些奇怪的原因,我放置在任何 gridview 中的所有按钮看起来都真的缩小了(如下图所示),即使 gridview 是默认的并且没有附加 CSS。 会不会是其他一些 CSS,因为我有太多代码无法
我目前正在实现一个身份验证系统,其中用户登录并从服务器接收 JWT token ,该 token 存储在 localStorage 中。我还编写了一个自定义 HttpInterceptor,它将用户的
我正在尝试使 QGridLayout 可滚动。它可能包含几个自定义小部件,小部件的数量不固定。当有超过 x 个小部件时,QGridLayout 必须是可滚动的,x 是任意数字。 问题是,当我使用 QS
更改我的系统 PATH 变量似乎把一切都搞砸了。 因此,我尝试运行 rake device:android:product 来制作我一直在使用 RhoMobile/Rhodes 开发的应用程序的 AP
我有一些中文字符(例如中文(简体))存储在内容类型为utf8_bin的mysql数据库中。 我使用以下代码从数据库中提取数据: if($stmt = $mysqli->prepare("SELECT
我们需要创建和销毁 QApplication 的实例,因为我们想在现有主机应用程序的插件中使用 Qt。 void multiQT() { int argc = 0; QApplicat
我是一名优秀的程序员,十分优秀!