将图像放置在 jmenubar 中 + j工具栏
我想知道是否可以将图像设置为 jmenubar+jtoolbar 的背景(不仅为其中之一,不是为每一个,而是为两者都设置)...
有人有想法吗? 如果可能的话我该怎么做?
谢谢 !
这里用一张图片来解释:
已解决::我使用了两个图像(剪切到正确的尺寸以适合我的 jmenubar+jtoolbar)并添加这些对对象的声明作为覆盖,效果很好!这是一段代码:
///////////////////////////////
JToolBar toolBar = new JToolBar(){
@Override
protected void paintComponent(Graphics g){
Image photo = getToolkit().getImage("src/MainFrame/Images/xtremeCalliBottom.png");
super.paintComponent(g) ;
int x=(mainFrame.getWidth()-200), y=0 ;
if(photo != null)
g.drawImage (photo, x, y, this);
}
};
// ............
//========== Menu Bar
jMenuBar = new JMenuBar(){
@Override
protected void paintComponent(Graphics g){
Image photo = getToolkit().getImage("src/MainFrame/Images/xtremeCalliTop.png");
super.paintComponent(g) ;
int x=(mainFrame.getWidth()-200), y=0 ;
if(photo != null)
g.drawImage (photo, x, y, this);
}
};
// ................
jMenuBar.setPreferredSize(new Dimension(100, 25));
toolBar.setPreferredSize(new Dimension(100,40));
I would like to know if it's possible to set an image as background for a jmenubar+jtoolbar (not only for one of theym, not one for each of theym But on for BOTH) ...
Anyone's got an idea ??
How should I do that if it's possible ?
Thanks !
Here an image to explain :
Solved :: I used two images (cutted to the right size to suite my jmenubar+jtoolbar) and added these to the object's declarations as overrides and it works great ! Here is a piece of code :
///////////////////////////////
JToolBar toolBar = new JToolBar(){
@Override
protected void paintComponent(Graphics g){
Image photo = getToolkit().getImage("src/MainFrame/Images/xtremeCalliBottom.png");
super.paintComponent(g) ;
int x=(mainFrame.getWidth()-200), y=0 ;
if(photo != null)
g.drawImage (photo, x, y, this);
}
};
// ............
//========== Menu Bar
jMenuBar = new JMenuBar(){
@Override
protected void paintComponent(Graphics g){
Image photo = getToolkit().getImage("src/MainFrame/Images/xtremeCalliTop.png");
super.paintComponent(g) ;
int x=(mainFrame.getWidth()-200), y=0 ;
if(photo != null)
g.drawImage (photo, x, y, this);
}
};
// ................
jMenuBar.setPreferredSize(new Dimension(100, 25));
toolBar.setPreferredSize(new Dimension(100,40));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然可以,但是您必须单独覆盖它们。您还需要保留一些全局变量(或可以在两者之间传递的变量),以便他们可以知道每个变量有多大。
您需要重写paintComponent() 或添加您自己的UI 委托来进行绘制。您可以加载图像并仅在菜单栏上绘制顶部部分(或相对百分比),然后仅在工具栏上绘制底部部分或相对百分比。
Sure, but you'll have to override them separately. You'll also need to keep some global variable (or one that you can pass between the two) so that they can know how big each of them are.
You'll need to override paintComponent() or add your own UI delegate to do the painting. You can load the image and paint just the top portion (or relative percentage) on the menubar, then paint just the bottom portion or relative percentage on the toolbar.