JTabbedPane上添加JPanel为何不显示???

tpfpcwl 2009-09-02 01:44:11
JTabbedPane上添加JPanel为何不显示???各种方法都试了,就是不行!!!网上也没找到解决方法。希望能在这里找到答案。。以下是我的源代码,望高手指点!
JTabbedPane子类如下:
package com.fei.bean;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import com.fei.main.BasicFrame;

public class LeftTabbedPaneBean extends JTabbedPane {
BasicFrame basicFrame = null;

public LeftTabbedPaneBean(BasicFrame basicFrame) {
this.basicFrame = basicFrame;
buildAndShow();
this.setPreferredSize(new Dimension(180,500));
}

public void buildAndShow() {
this.addTab("系统功能", basicFrame.getBasicFunctionPanelBean());
this.addTab("地理查询", basicFrame.getQueryPanelBean());
this.setTabPlacement(JTabbedPane.BOTTOM);
this.setVisible(true);


}

}


要添加的JPanel代码如下:
package com.fei.bean;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;

import com.esri.arcgis.beans.TOC.TOCBean;
import com.esri.arcgis.beans.map.MapBean;
import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.carto.IMap;
import com.esri.arcgis.systemUI.ICommand;
import com.esri.arcgis.systemUI.ITool;
import com.fei.main.BasicFrame;
import com.fei.query.CheckNode;
import com.fei.query.CheckNodeTree;
import com.fei.query.LatelySearchJDialog;
import com.fei.query.MyCircularQuery;
import com.fei.query.MyLikeQuery;
import com.fei.query.MyPointQuery;
import com.fei.query.MyPolygonQuery;
import com.fei.query.MyRectangleQuery;
import com.fei.query.NearbySearchJDialog;
import com.fei.resources.Resources;
import com.fei.resources.icons.Icon;

/**
*
* 定义查询面板,该面板继承Jpanel
*
*/
@SuppressWarnings("serial")
public class QueryPanelBean extends JPanel {

private BasicFrame basicFrame = null;
// 树
private CheckNodeTree tree;
// // 树Model
private DefaultTreeModel model;
// 树根
private DefaultMutableTreeNode root;
// 周边查询树
private CheckNodeTree treeNearBy;
// 周边查询树Model
private DefaultTreeModel modelNearBy;
// 周边查询树根
private DefaultMutableTreeNode rootNearBy;
// 最近查询树
private CheckNodeTree treeLately;
// 最近查询树Model
private DefaultTreeModel modelLately;
// 最近查询树根
private DefaultMutableTreeNode rootLately;
// 查询工具
private JPanel borderPanel = null;

private JPanel gridPanel = null;
// 查询button
private JButton searchButton = null;
// 点选查询button
private JButton pointSearchButton = null;
// 圆形查询
private JButton circularSelectSearch = null;
// 矩形查询
private JButton rectangleSearch = null;
// 多边形查询
private JButton polygonSearch = null;
// 周边查询
private JButton nearbySearch = null;
// 最近查询
private JButton latelySearch = null;
// 清除查询结果
private JButton clearSearchResult = null;
// 关键字
private JTextField key = null;
// 关闭按钮
private JButton shutbutton = null;
// 查询启动时加载面板
private JLabel splashLabel = null;
private JFrame splashScreen = null;

EmptyBorder border5 = new EmptyBorder(5, 5, 5, 5);

public QueryPanelBean(BasicFrame basicFrame) {
this.basicFrame = basicFrame;
buildAndShow();
}

public void buildAndShow() {
BorderLayout borderLayout = new BorderLayout();
this.setLayout(borderLayout);
// 请选择查询图层
JLabel selectMapLayer = new JLabel();
shutbutton = new JButton(new ImageIcon(Resources.getIcon(Icon.class,
"generic/editcut.gif")));
// 按钮的动态缩放
shutbutton.setMargin(new Insets(0, 0, 0, 0));
shutbutton.setBorder(null);
JPanel toppanel = new JPanel();
selectMapLayer.setText("PleaseSelectMapLayer");

// 图层列表
root = new DefaultMutableTreeNode("TocRoot");
model = new DefaultTreeModel(root);
tree = new CheckNodeTree(model);
tree.setRootVisible(false);

// 周边查询树列表
rootNearBy = new DefaultMutableTreeNode("TocRoot");
modelNearBy = new DefaultTreeModel(rootNearBy);
treeNearBy = new CheckNodeTree(modelNearBy);
treeNearBy.setRootVisible(false);

// 最近查询树列表
rootLately = new DefaultMutableTreeNode("TocRoot");
modelLately = new DefaultTreeModel(rootLately);
treeLately = new CheckNodeTree(modelLately);
treeLately.setRootVisible(false);

// 查询工具
borderPanel = new JPanel();
borderPanel.setLayout(new BorderLayout());
borderPanel.setBorder(new CompoundBorder(new TitledBorder(null,
"PanelTitle", TitledBorder.LEFT,
TitledBorder.TOP), border5));

// GridPanel
gridPanel = new JPanel();
gridPanel.setLayout(new GridLayout(4, 2, 5, 5));

key = new JTextField();
key.setColumns(9);

searchButton = new JButton();
searchButton.setText("SearchButton");

pointSearchButton = new JButton();
pointSearchButton.setText("PointSearchButton");

circularSelectSearch = new JButton();
circularSelectSearch.setText("CircularSelectSearch");

rectangleSearch = new JButton();
rectangleSearch.setText("RectangleSearch");

polygonSearch = new JButton();
polygonSearch.setText("PolygonSearch");

nearbySearch = new JButton();
nearbySearch.setText("NearbySearch");
nearbySearch.setEnabled(false);

latelySearch = new JButton();
latelySearch.setText("LatelySearch");
latelySearch.setEnabled(false);

gridPanel.add(key);
gridPanel.add(searchButton);
gridPanel.add(pointSearchButton);
gridPanel.add(circularSelectSearch);
gridPanel.add(rectangleSearch);
gridPanel.add(polygonSearch);
gridPanel.add(nearbySearch);
gridPanel.add(latelySearch);

clearSearchResult = new JButton();
clearSearchResult.setText("ClearSearchResult");
JPanel panel = new JPanel();
panel.add(clearSearchResult);

borderPanel.add(
new JLabel("PleaseAddrInfo"),
BorderLayout.NORTH);
borderPanel.add(gridPanel, BorderLayout.CENTER);
borderPanel.add(panel, BorderLayout.SOUTH);

JScrollPane scrollPane = new JScrollPane(tree);
scrollPane.setBorder(BorderFactory.createLoweredBevelBorder());

toppanel.setLayout(new BorderLayout());
toppanel.add(selectMapLayer, BorderLayout.WEST);
toppanel.add(shutbutton, BorderLayout.EAST);
this.add(toppanel, BorderLayout.NORTH);
this.add(scrollPane, BorderLayout.CENTER);
this.add(borderPanel, BorderLayout.SOUTH);

}
在这里先谢谢各位了。
...全文
558 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tpfpcwl 2009-09-02
  • 打赏
  • 举报
回复
谢谢各位了啊!
justinavril 2009-09-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 tpfpcwl 的回复:]
这样简单的添加到一个窗口,是能添加上可以显示。但是一放到我的主界面上添加就不显示了。
[/Quote]
道理是一样的 我感觉还是你添加的顺序有问题
tpfpcwl 2009-09-02
  • 打赏
  • 举报
回复
这样简单的添加到一个窗口,是能添加上可以显示。但是一放到我的主界面上添加就不显示了。
justinavril 2009-09-02
  • 打赏
  • 举报
回复
还有就是导入包的话 最好不要那么详细吧 看着都晕了
一句import java.awt.*就好了
justinavril 2009-09-02
  • 打赏
  • 举报
回复
你的代码有点复杂,但是把JPanel对象添加到tab中去的过程可以简单一点,给出示意代码:

import javax.swing.*;

public class JTabbedTest extends JFrame{
public static void main(String[] args){
JTabbedTest frame = new JTabbedTest();

frame.setSize(300,300);
frame.setVisible(true);

}

public JTabbedTest(){
final JTabbedPane jtp = new JTabbedPane();

JPanel jp1 = new JPanel();
JButton jb1 = new JButton( "This is a button!" );
jp1.add(jb1);

jtp.add( "first", jp1 );

getContentPane().add( jtp );
}
}
imasmallbird 2009-09-02
  • 打赏
  • 举报
回复
basicFrame.getBasicFunctionPanelBean()与
basicFrame.getQueryPanelBean()这都返回你想要的JPanel了吗?

62,636

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧