我的JTabbedPane实现不了选项卡改变其对应的Jpanel的功能,高手帮帮改一下。谢谢! 5
/**音乐共享平台主窗体*/packagecom.pb.devj.demo;importjava.awt.Color;importjava.awt.Dimension;i...
/*
* 音乐共享平台主窗体
*/
package com.pb.devj.demo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class myJFrameM extends JFrame {
public JPanel mainJPanel;
public JPanel songJPanel;
public JPanel downloadJPanel;
public JPanel myMusicJPanel;
public JTabbedPane tab;
public myJFrameM(){
tab = new JTabbedPane(JTabbedPane.TOP);
tab.setOpaque(false);
tab.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
setTitle("音乐共享平台");
final Image jtImage = new ImageIcon("D:/PB项目素材/参与人员使用素材./main.jpg").getImage();
setSize(new Dimension(jtImage.getWidth(null),jtImage.getHeight(null)));
//将背景图绘制在Panel面板中
JPanel jtPanel =new JPanel(){
public void paint(Graphics g){
g.drawImage(jtImage,0,0,null);
super.paint(g);
}
};
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
add(jtPanel);
jtPanel.setOpaque(false);
jtPanel.setLayout(null);
jtPanel.add(tab);
tab.setBounds(0,40,946,460);
//够建Tap选项卡
tab.addTab("主窗口",mainJPanel);
tab.addTab("歌曲列表",songJPanel);
tab.addTab("下载列表",downloadJPanel);
tab.addTab("我的音乐",myMusicJPanel);
//添加窗体
// tab.add( mainJPanel,0);
//tab.add( songJPanel,1);
// tab.add( downloadJPanel,2);
// tab.add( myMusicJPanel,3);
mainJPanel=new JPanel();
mainJPanel.setSize(946,460 );
mainJPanel.setBackground(Color.white);
mainJPanel.setVisible(true);
mainJPanel.setOpaque(false);
songJPanel=new JPanel();
songJPanel.setSize(946,460 );
songJPanel.setBackground(Color.RED);
songJPanel.setVisible(true);
songJPanel.setOpaque(false);
downloadJPanel=new JPanel();
downloadJPanel.setSize(946,460 );
downloadJPanel.setBackground(Color.white);
downloadJPanel.setVisible(true);
downloadJPanel.setOpaque(false);
myMusicJPanel=new JPanel();
myMusicJPanel.setSize(946,460 );
myMusicJPanel.setBackground(Color.white);
myMusicJPanel.setVisible(true);
myMusicJPanel.setOpaque(false);
}
public static void main(String[] arg){
myJFrameM f1= new myJFrameM ();
}
} 展开
* 音乐共享平台主窗体
*/
package com.pb.devj.demo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class myJFrameM extends JFrame {
public JPanel mainJPanel;
public JPanel songJPanel;
public JPanel downloadJPanel;
public JPanel myMusicJPanel;
public JTabbedPane tab;
public myJFrameM(){
tab = new JTabbedPane(JTabbedPane.TOP);
tab.setOpaque(false);
tab.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
setTitle("音乐共享平台");
final Image jtImage = new ImageIcon("D:/PB项目素材/参与人员使用素材./main.jpg").getImage();
setSize(new Dimension(jtImage.getWidth(null),jtImage.getHeight(null)));
//将背景图绘制在Panel面板中
JPanel jtPanel =new JPanel(){
public void paint(Graphics g){
g.drawImage(jtImage,0,0,null);
super.paint(g);
}
};
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
add(jtPanel);
jtPanel.setOpaque(false);
jtPanel.setLayout(null);
jtPanel.add(tab);
tab.setBounds(0,40,946,460);
//够建Tap选项卡
tab.addTab("主窗口",mainJPanel);
tab.addTab("歌曲列表",songJPanel);
tab.addTab("下载列表",downloadJPanel);
tab.addTab("我的音乐",myMusicJPanel);
//添加窗体
// tab.add( mainJPanel,0);
//tab.add( songJPanel,1);
// tab.add( downloadJPanel,2);
// tab.add( myMusicJPanel,3);
mainJPanel=new JPanel();
mainJPanel.setSize(946,460 );
mainJPanel.setBackground(Color.white);
mainJPanel.setVisible(true);
mainJPanel.setOpaque(false);
songJPanel=new JPanel();
songJPanel.setSize(946,460 );
songJPanel.setBackground(Color.RED);
songJPanel.setVisible(true);
songJPanel.setOpaque(false);
downloadJPanel=new JPanel();
downloadJPanel.setSize(946,460 );
downloadJPanel.setBackground(Color.white);
downloadJPanel.setVisible(true);
downloadJPanel.setOpaque(false);
myMusicJPanel=new JPanel();
myMusicJPanel.setSize(946,460 );
myMusicJPanel.setBackground(Color.white);
myMusicJPanel.setVisible(true);
myMusicJPanel.setOpaque(false);
}
public static void main(String[] arg){
myJFrameM f1= new myJFrameM ();
}
} 展开
1个回答
展开全部
// 设置透明后,底色无效!
// 首先创建Panel,把它亩码new出来之后,再放到tabpane中。
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class myJFrameM extends JFrame {
public JPanel mainJPanel;
public JPanel songJPanel;
public JPanel downloadJPanel;
public JPanel myMusicJPanel;
public JTabbedPane tab;
public myJFrameM() {
tab = new JTabbedPane(JTabbedPane.TOP);
tab.setOpaque(false);
tab.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
setTitle("音乐共享平台");
final Image jtImage = new ImageIcon("D:/PB项目素材/参与人员使用素材./main.jpg")
.getImage();
setSize(new Dimension(jtImage.getWidth(null), jtImage.getHeight(null)));
// 将背告耐态景图绘制袜源在Panel面板中
JPanel jtPanel = new JPanel() {
public void paint(Graphics g) {
g.drawImage(jtImage, 0, 0, null);
super.paint(g);
}
};
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
add(jtPanel);
jtPanel.setOpaque(false);
jtPanel.setLayout(null);
jtPanel.add(tab);
tab.setBounds(0, 40, 946, 460);
//
// // 添加窗体
// tab.add( mainJPanel,0);
// tab.add( songJPanel,1);
// tab.add( downloadJPanel,2);
// tab.add( myMusicJPanel,3);
mainJPanel = new JPanel();
// mainJPanel.setSize(946, 460);
mainJPanel.setBackground(Color.white);
// mainJPanel.setVisible(true);
// mainJPanel.setOpaque(false);
songJPanel = new JPanel();
// songJPanel.setSize(946, 460);
songJPanel.setBackground(Color.RED);
// songJPanel.setVisible(true);
// songJPanel.setOpaque(false);
downloadJPanel = new JPanel();
// downloadJPanel.setSize(946, 460);
downloadJPanel.setBackground(Color.white);
// downloadJPanel.setVisible(true);
// downloadJPanel.setOpaque(false);
myMusicJPanel = new JPanel();
// myMusicJPanel.setSize(946, 460);
myMusicJPanel.setBackground(Color.white);
// myMusicJPanel.setVisible(true);
// myMusicJPanel.setOpaque(false);
// 够建Tap选项卡
tab.addTab("主窗口", mainJPanel);
tab.addTab("歌曲列表", songJPanel);
tab.addTab("下载列表", downloadJPanel);
tab.addTab("我的音乐", myMusicJPanel);
}
public static void main(String[] arg) {
myJFrameM f1 = new myJFrameM();
}
}
// 首先创建Panel,把它亩码new出来之后,再放到tabpane中。
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class myJFrameM extends JFrame {
public JPanel mainJPanel;
public JPanel songJPanel;
public JPanel downloadJPanel;
public JPanel myMusicJPanel;
public JTabbedPane tab;
public myJFrameM() {
tab = new JTabbedPane(JTabbedPane.TOP);
tab.setOpaque(false);
tab.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
setTitle("音乐共享平台");
final Image jtImage = new ImageIcon("D:/PB项目素材/参与人员使用素材./main.jpg")
.getImage();
setSize(new Dimension(jtImage.getWidth(null), jtImage.getHeight(null)));
// 将背告耐态景图绘制袜源在Panel面板中
JPanel jtPanel = new JPanel() {
public void paint(Graphics g) {
g.drawImage(jtImage, 0, 0, null);
super.paint(g);
}
};
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
add(jtPanel);
jtPanel.setOpaque(false);
jtPanel.setLayout(null);
jtPanel.add(tab);
tab.setBounds(0, 40, 946, 460);
//
// // 添加窗体
// tab.add( mainJPanel,0);
// tab.add( songJPanel,1);
// tab.add( downloadJPanel,2);
// tab.add( myMusicJPanel,3);
mainJPanel = new JPanel();
// mainJPanel.setSize(946, 460);
mainJPanel.setBackground(Color.white);
// mainJPanel.setVisible(true);
// mainJPanel.setOpaque(false);
songJPanel = new JPanel();
// songJPanel.setSize(946, 460);
songJPanel.setBackground(Color.RED);
// songJPanel.setVisible(true);
// songJPanel.setOpaque(false);
downloadJPanel = new JPanel();
// downloadJPanel.setSize(946, 460);
downloadJPanel.setBackground(Color.white);
// downloadJPanel.setVisible(true);
// downloadJPanel.setOpaque(false);
myMusicJPanel = new JPanel();
// myMusicJPanel.setSize(946, 460);
myMusicJPanel.setBackground(Color.white);
// myMusicJPanel.setVisible(true);
// myMusicJPanel.setOpaque(false);
// 够建Tap选项卡
tab.addTab("主窗口", mainJPanel);
tab.addTab("歌曲列表", songJPanel);
tab.addTab("下载列表", downloadJPanel);
tab.addTab("我的音乐", myMusicJPanel);
}
public static void main(String[] arg) {
myJFrameM f1 = new myJFrameM();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询