swing 中的工具栏问题 +爪哇
我的文件中有这段代码,
String[] iconFiles = { "state.jpg", "cursor.jpg", "arrow.jpg" };
String[] buttonLabels = { "New Node", "Attribute Change", "Add Edge"};
for (int i = 0; i < buttonLabels.length; ++i) {
icons[i] = new ImageIcon(iconFiles[i]);
buttons[i] = new JButton(icons[i]);
buttons[i].setToolTipText(buttonLabels[i]);
buttons[i].setPreferredSize(new java.awt.Dimension(648, 600));
toolBar.add(buttons[i]);
toolBar.addSeparator();
}
jp2.add(toolBar) where jp2 is a Tabbed Pane
我有两个问题。
首先,由图标表示的图像文件不会自行调整大小,因此会被按钮大小剪切。
其次,工具栏显示在窗口中,但我可以将其拖到某种新窗口中。我怎样才能防止这种情况发生?
I have this code in my file
String[] iconFiles = { "state.jpg", "cursor.jpg", "arrow.jpg" };
String[] buttonLabels = { "New Node", "Attribute Change", "Add Edge"};
for (int i = 0; i < buttonLabels.length; ++i) {
icons[i] = new ImageIcon(iconFiles[i]);
buttons[i] = new JButton(icons[i]);
buttons[i].setToolTipText(buttonLabels[i]);
buttons[i].setPreferredSize(new java.awt.Dimension(648, 600));
toolBar.add(buttons[i]);
toolBar.addSeparator();
}
jp2.add(toolBar) where jp2 is a Tabbed Pane
I have 2 questions in this.
Firstly the image file that is represented by the icon does not get resized on its own and thus gets cut by the button size.
Secondly the toolbar gets shown in the window but I am able to drag it out into a sort of a new window. How can I prevent this from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
A)可以使用以下代码重新缩放图标中的图像:
B)可以将
JToolBar
设为不可浮动,这就是我认为您想要的:A) The image in the icon can be rescaled using the following code:
B) The
JToolBar
can be made unfloatable which is what I think you want: