解决方案 »
- 将RESULT传给10个Thread运行问题
- [求助]想把带Checkbox的JTree改造成单态树,试图对TreePath做改造不成功,请求指点思路!
- ListCellRenderer接口使用问题。。。
- 调用本地程序
- 请问 javax.xml 与 org.w3c.xml的区别
- 在随机数中怎样把数字转换成字符串
- 无参数构造函数和有参数构造函数的区别在哪里? 有参数构造函数和类默认的构造函数的优势体现在那里?望高手指点,小第初学JAVA
- int 与 Integer 的区别?
- 我刚刚开始学习java,有人能帮帮我吗?
- Object和Integer
- 算法题:找出一个数组中前K个大数的位置
- 求大神给个思路,真心没有思路啊
private void initialize() {
setBackground(new Color(240, 248, 255));
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{350, 0};
gridBagLayout.rowHeights = new int[]{500, 0};
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
setLayout(gridBagLayout);
JScrollPane speOutputWindow = new JScrollPane();
speOutputWindow.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
GridBagConstraints gbc_speOutputWindow = new GridBagConstraints();
gbc_speOutputWindow.fill = GridBagConstraints.BOTH;
gbc_speOutputWindow.gridx = 0;
gbc_speOutputWindow.gridy = 0;
add(speOutputWindow, gbc_speOutputWindow);
speOutputWindow.setAlignmentY(Component.TOP_ALIGNMENT);
speOutputWindow.setAlignmentX(Component.LEFT_ALIGNMENT);
JPanel panel = new JPanel();
panel.setBackground(new Color(240, 248, 255));
speOutputWindow.setViewportView(panel);
GridBagLayout gbl_plTotal = new GridBagLayout();
gbl_plTotal.columnWidths = new int[] { 10, 200, 10};
gbl_plTotal.rowHeights = new int[] { 0};
gbl_plTotal.columnWeights = new double[] { 0.0, 1.0, 0.0 };
gbl_plTotal.rowWeights = new double[] { 1.0};
panel.setLayout(gbl_plTotal);
ArrayList<String> message = new ArrayList<String>();
message.add("test1");
message.add("test2");
message.add("test3");
message.add("test4");
message.add("test5");
message.add("test6");
message.add("test7");
message.add("test8");
message.add("test9");
message.add("test10");
// for (int i = 0; i < 5; i++) {
int i = 0;
OtherChatPanel plOtherBoard = new OtherChatPanel("other", message.get(2*i), "2014/01/10 9:14:30");
GridBagConstraints gbc_plOtherBoard = new GridBagConstraints();
//gbc_plOtherBoard.insets = new Insets(0, 0, 5, 5);
gbc_plOtherBoard.fill = GridBagConstraints.HORIZONTAL;
gbc_plOtherBoard.anchor = GridBagConstraints.LAST_LINE_START;
gbc_plOtherBoard.gridx = 1;
gbc_plOtherBoard.gridy = 2*i;
//gbc_plOtherBoard.
panel.add(plOtherBoard, gbc_plOtherBoard);
MyChatPanel plMyBoard = new MyChatPanel("self", message.get(2*i+1),
"2014/01/10 9:14:50");
GridBagConstraints gbc_plMyBoard = new GridBagConstraints();
//gbc_plMyBoard.insets = new Insets(0, 0, 5, 5);
gbc_plMyBoard.fill = GridBagConstraints.HORIZONTAL;
gbc_plMyBoard.anchor = GridBagConstraints.LAST_LINE_END;
gbc_plMyBoard.gridx = 1;
gbc_plMyBoard.gridy = 2*i + 1;
panel.add(plMyBoard, gbc_plMyBoard);
}
我没试楼主给的代码。(代码不全,不好调试)。不过,可以肯定的是,GridBagLayout 是可以自适应!