实现类似QQ好友列表功能,int i表示有i个好友,生成i个JPanel
我的代码如下,存在问题,没法正常显示。请高手指点
int i=6;
final JPanel panel[i];
final JLabel face[i];
final JLabel ID[i];
for(j=0;j<=i;j++)
{
panel[j] = new JPanel();
panel[j].setLayout(null);
panel[j].setBounds(25, 21*j+21, 94, 29);
frame.getContentPane().add(panel[j]); face[j] = DefaultComponentFactory.getInstance().createLabel("face");
face[j].setBounds(0, 0, 29, 29);
panel[j].add(face[j]); ID[j] = DefaultComponentFactory.getInstance().createLabel("ID");
ID[j].setBounds(31, 6, 63, 17);
panel[j].add(ID[j]);
}
我的代码如下,存在问题,没法正常显示。请高手指点
int i=6;
final JPanel panel[i];
final JLabel face[i];
final JLabel ID[i];
for(j=0;j<=i;j++)
{
panel[j] = new JPanel();
panel[j].setLayout(null);
panel[j].setBounds(25, 21*j+21, 94, 29);
frame.getContentPane().add(panel[j]); face[j] = DefaultComponentFactory.getInstance().createLabel("face");
face[j].setBounds(0, 0, 29, 29);
panel[j].add(face[j]); ID[j] = DefaultComponentFactory.getInstance().createLabel("ID");
ID[j].setBounds(31, 6, 63, 17);
panel[j].add(ID[j]);
}
解决方案 »
- java创建对象时的栈溢出的问题
- 菜鸟级求高手帮改下约瑟夫问题的代码 下面的代码是最后显示2/1人数的最后一位,我希望的是后面显示生存人的序号,而不是最后一个死亡人的序号
- 直接用java(不用预先编译为.class)命令运行.java文件是什么原理?
- HsqlDB中的session问题
- Hibernate中的关联维护
- csdn的大虾们帮帮忙啊,如何提取数据库中数据并形成试卷
- sendmail的问题
- 送分就是爽继续:)
- 如何学习java,类库???请大家一定来看看!
- 那里有下载JBUILDER5.0完整版??? 谢谢
- 这就怪了! JAVA 里 byte 类型 可以存储值的范围是 -128~127!
- redirect和forword
是不是只能显示一个?
我认为你的frame和panel都应该设置布局而且你这个列表的设计并不是太好,有现成的jlist你为什么不用呢
panel[j].setLayout(null); // 注意, 这里设置的是panel[j]的Layout为null, 而不是设置frame.getContentPane()取得的content pane的Layout为null, 而你是把panel[j]加到frame的content pane中去, content pane是容器, 所以应该设置 content pane的Layout为null.
panel[j].setBounds(25, 21*j+21, 94, 29);
frame.getContentPane().add(panel[j]);
二楼的能不能给个jlist的教程,我刚刚开始学swt
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.examples.controlexample;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;class ListTab extends ScrollableTab { /* Example widgets and groups that contain them */
List list1;
Group listGroup;
static String [] ListData1 = {ControlExample.getResourceString("ListData1_0"),
ControlExample.getResourceString("ListData1_1"),
ControlExample.getResourceString("ListData1_2"),
ControlExample.getResourceString("ListData1_3"),
ControlExample.getResourceString("ListData1_4"),
ControlExample.getResourceString("ListData1_5"),
ControlExample.getResourceString("ListData1_6"),
ControlExample.getResourceString("ListData1_7"),
ControlExample.getResourceString("ListData1_8")}; /**
* Creates the Tab within a given instance of ControlExample.
*/
ListTab(ControlExample instance) {
super(instance);
}
/**
* Creates the "Example" group.
*/
void createExampleGroup () {
super.createExampleGroup ();
/* Create a group for the list */
listGroup = new Group (exampleGroup, SWT.NONE);
listGroup.setLayout (new GridLayout ());
listGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
listGroup.setText ("List");
}
/**
* Creates the "Example" widgets.
*/
void createExampleWidgets () {
/* Compute the widget style */
int style = getDefaultStyle();
if (singleButton.getSelection ()) style |= SWT.SINGLE;
if (multiButton.getSelection ()) style |= SWT.MULTI;
if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
if (borderButton.getSelection ()) style |= SWT.BORDER;
/* Create the example widgets */
list1 = new List (listGroup, style);
list1.setItems (ListData1);
}
/**
* Gets the "Example" widget children.
*/
Widget [] getExampleWidgets () {
return new Widget [] {list1};
}
/**
* Returns a list of set/get API method names (without the set/get prefix)
* that can be used to set/get values in the example control(s).
*/
String[] getMethodNames() {
return new String[] {"Items", "Selection", "ToolTipText", "TopIndex"};
} /**
* Gets the text for the tab folder item.
*/
String getTabText () {
return "List";
}
}