Java JTabbedPane 用法?
哪位童鞋能给个带多标签页的桌面应用程序实例代码~现在想做个像360安全卫士那样上面一行带标签点不同的标签时主界面内容随之改变的东西...不知道说清楚了没有...模糊的童鞋...
哪位童鞋 能给个 带 多标签页的桌面应用程序 实例代码~
现在想做个像360安全卫士 那样 上面一行带标签 点不同的标签时
主界面内容随之改变的东西 ... 不知道说清楚了没有... 模糊的童鞋可以提问 在线等~
用Java~ 展开
现在想做个像360安全卫士 那样 上面一行带标签 点不同的标签时
主界面内容随之改变的东西 ... 不知道说清楚了没有... 模糊的童鞋可以提问 在线等~
用Java~ 展开
3个回答
展开全部
@SuppressWarnings("serial")
public class JTabbedDemo extends JFrame {
private JTabbedPane tab;
public JTabbedDemo(){
tabType();
tab = new JTabbedPane(JTabbedPane.LEFT);
tab.addTab("线形", new BorderPanel(BorderFactory.createLineBorder(Color.BLUE, 5)));
tab.addTab("圆角", new BorderPanel(new LineBorder(Color.GRAY,5,true)));
tab.addTab("三维效应", new BorderPanel(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)));
tab.addTab("斜教", new BorderPanel(BorderFactory.createRaisedBevelBorder()));
tab.addTab("软斜角", new BorderPanel(new SoftBevelBorder(SoftBevelBorder.LOWERED)));
tab.addTab("组合", new BorderPanel(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(15, 15, 15, 15), new LineBorder(Color.gray,2,true))));
tab.addTab("标题", new BorderPanel(BorderFactory.createTitledBorder(
BorderFactory.createLineBorder(Color.GRAY), "Nagisa", TitledBorder.CENTER,
TitledBorder.TOP, new Font("微软雅黑", Font.BOLD, 20), Color.BLUE)));
tab.addTab("图形", new BorderPanel(BorderFactory.createMatteBorder(50, 50, 50, 50,
new ImageIcon(System.getProperty("user.dir") + "/img/han.gif"))));
add(tab);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private void tabType(){
ItemListener l = new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e) {
String text = ((JRadioButton)e.getItem()).getText();
if(text.equals("Left")){
tab.setTabPlacement(JTabbedPane.LEFT);
}else if(text.equals("Right")){
tab.setTabPlacement(JTabbedPane.RIGHT);
}else if(text.equals("Top")){
tab.setTabPlacement(JTabbedPane.TOP);
}else{
tab.setTabPlacement(JTabbedPane.BOTTOM);
}
}
};
JPanel p = new JPanel();
ButtonGroup group = new ButtonGroup();
JRadioButton radio = new JRadioButton("Left",true);
radio.addItemListener(l);
group.add(radio);
p.add(radio);
radio = new JRadioButton("Right");
radio.addItemListener(l);
group.add(radio);
p.add(radio);
radio = new JRadioButton("Top");
radio.addItemListener(l);
group.add(radio);
p.add(radio);
radio = new JRadioButton("Bottom");
radio.addItemListener(l);
group.add(radio);
p.add(radio);
add(p,BorderLayout.NORTH);
}
public static void main(String[] args){
new JTabbedDemo();
}
}
@SuppressWarnings("serial")
class BorderPanel extends JPanel {
private Insets inset;
private int w;
private int h;
public BorderPanel(Border b){
inset = getInsets();
w = 600 + inset.left + inset.right;
h = 800 + inset.top + inset.bottom;
setPreferredSize(new Dimension(w,h));
setBorder(b);
}
}
public class JTabbedDemo extends JFrame {
private JTabbedPane tab;
public JTabbedDemo(){
tabType();
tab = new JTabbedPane(JTabbedPane.LEFT);
tab.addTab("线形", new BorderPanel(BorderFactory.createLineBorder(Color.BLUE, 5)));
tab.addTab("圆角", new BorderPanel(new LineBorder(Color.GRAY,5,true)));
tab.addTab("三维效应", new BorderPanel(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)));
tab.addTab("斜教", new BorderPanel(BorderFactory.createRaisedBevelBorder()));
tab.addTab("软斜角", new BorderPanel(new SoftBevelBorder(SoftBevelBorder.LOWERED)));
tab.addTab("组合", new BorderPanel(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(15, 15, 15, 15), new LineBorder(Color.gray,2,true))));
tab.addTab("标题", new BorderPanel(BorderFactory.createTitledBorder(
BorderFactory.createLineBorder(Color.GRAY), "Nagisa", TitledBorder.CENTER,
TitledBorder.TOP, new Font("微软雅黑", Font.BOLD, 20), Color.BLUE)));
tab.addTab("图形", new BorderPanel(BorderFactory.createMatteBorder(50, 50, 50, 50,
new ImageIcon(System.getProperty("user.dir") + "/img/han.gif"))));
add(tab);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private void tabType(){
ItemListener l = new ItemListener(){
@Override
public void itemStateChanged(ItemEvent e) {
String text = ((JRadioButton)e.getItem()).getText();
if(text.equals("Left")){
tab.setTabPlacement(JTabbedPane.LEFT);
}else if(text.equals("Right")){
tab.setTabPlacement(JTabbedPane.RIGHT);
}else if(text.equals("Top")){
tab.setTabPlacement(JTabbedPane.TOP);
}else{
tab.setTabPlacement(JTabbedPane.BOTTOM);
}
}
};
JPanel p = new JPanel();
ButtonGroup group = new ButtonGroup();
JRadioButton radio = new JRadioButton("Left",true);
radio.addItemListener(l);
group.add(radio);
p.add(radio);
radio = new JRadioButton("Right");
radio.addItemListener(l);
group.add(radio);
p.add(radio);
radio = new JRadioButton("Top");
radio.addItemListener(l);
group.add(radio);
p.add(radio);
radio = new JRadioButton("Bottom");
radio.addItemListener(l);
group.add(radio);
p.add(radio);
add(p,BorderLayout.NORTH);
}
public static void main(String[] args){
new JTabbedDemo();
}
}
@SuppressWarnings("serial")
class BorderPanel extends JPanel {
private Insets inset;
private int w;
private int h;
public BorderPanel(Border b){
inset = getInsets();
w = 600 + inset.left + inset.right;
h = 800 + inset.top + inset.bottom;
setPreferredSize(new Dimension(w,h));
setBorder(b);
}
}
展开全部
jTabbedPane基本实现的例子:
package sony;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class JTablepanel extends JFrame {
private static final long serialVersionUID = -4519715771011652073L;
JTabbedPane tp = new JTabbedPane(JTabbedPane.TOP);
JPanel p1 = new JPanel();
JButton btn_1 = new JButton("按钮1");
JButton btn_2 = new JButton("按钮2");
JButton btn_3 = new JButton("按钮3");
JButton btn_4 = new JButton("按钮4");
JButton btn_5 = new JButton("按钮5");
public JTablepanel(){
getContentPane().add(p1);
p1.add(tp);
tp.add(btn_1);
tp.add(btn_2,1);
}
public static void main(String[] args) {
JTablepanel a = new JTablepanel();
a.setSize(300, 300);
a.setVisible(true);
}
}
package sony;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class JTablepanel extends JFrame {
private static final long serialVersionUID = -4519715771011652073L;
JTabbedPane tp = new JTabbedPane(JTabbedPane.TOP);
JPanel p1 = new JPanel();
JButton btn_1 = new JButton("按钮1");
JButton btn_2 = new JButton("按钮2");
JButton btn_3 = new JButton("按钮3");
JButton btn_4 = new JButton("按钮4");
JButton btn_5 = new JButton("按钮5");
public JTablepanel(){
getContentPane().add(p1);
p1.add(tp);
tp.add(btn_1);
tp.add(btn_2,1);
}
public static void main(String[] args) {
JTablepanel a = new JTablepanel();
a.setSize(300, 300);
a.setVisible(true);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上在哪复制的啊? 这么简单用说那么多吗?
JTabbedPane jtbp1=new JTabbedPane();
JPanel jp1 = new JPanel();
// panel 里爱放啥放啥
JPanel jp2 = new JPanel();
// panel 里爱放啥放啥
jtbp1.add("学生资料管理", jp1);
jtbp1.add("学生资料管理", jp2);
在生成 jFrame 时把 this.add(jtbp1 ) , 进去就行了
JTabbedPane jtbp1=new JTabbedPane();
JPanel jp1 = new JPanel();
// panel 里爱放啥放啥
JPanel jp2 = new JPanel();
// panel 里爱放啥放啥
jtbp1.add("学生资料管理", jp1);
jtbp1.add("学生资料管理", jp2);
在生成 jFrame 时把 this.add(jtbp1 ) , 进去就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询