Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

problem with JList, JSplitPane and JScrollPane

  Asked By: Ryan    Date: Sep 18    Category: Java    Views: 1290
  

I design my user interface manually coz I didnt have any gui builder
tools :)

When I use JScrollPane inside JSplitPane, I notice that when I type in
JTextArea, it didnt show the scrollbar. But when I try to resize the
are by dragging split pane, i can see the scrollbar...but it didnt do
correctly like I want. can someone recommended to me what I have to do
?

second question, how to make the size of JList constant ?
when I insert the data into list (for example String[] data={"one",
"two","three"} .. the width of the JList reduced ..... i didnt like
this ... can someone tell me how to overcome this problem ?

and here is the code

import javax.swing.*;
import java.awt.* ;
import java.awt.event.*;
import javax.swing.ImageIcon;

public class GUI {

public static void main(String[] args) {
myFrame frame = new myFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.show();
}
}


class myFrame extends JFrame
{
public myFrame(){
setTitle(title);
setSize(WIDTH, HEIGHT);

Container contentPane = getContentPane() ;

viewPane = new JTextArea();
viewPane.setPreferredSize(new Dimension(300,350));
JScrollPane viewPaneScroller = new JScrollPane(viewPane);

peopleList = new JList();
peopleList.setPreferredSize(new Dimension(20,350));
peopleList.setMinimumSize(new Dimension(30,350));
JScrollPane peopleListScroller = new
JScrollPane(peopleList);

JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
viewPaneScroller, peopleListScroller);
sp.setOneTouchExpandable(true);
sp.setDividerLocation(400);

JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout(FlowLayout.LEFT));

northPanel.add(sp);
contentPane.add(northPanel, BorderLayout.NORTH);

messageField = new JTextField(40);
ImageIcon sendIcon = new ImageIcon(getIconDir()+"send.gif")
;
sendButton = new JButton("Send", sendIcon);

JPanel southPanel = new JPanel();
southPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
southPanel.add(messageField);
southPanel.add(sendButton);

contentPane.add(southPanel, BorderLayout.SOUTH);

}


private static String getIconDir() {
return iconDir;
}


private static String getEmoticonsDir() {
return emoticonsDir;
}


private static final String title = "myRoom";
public static final int WIDTH = 800 ;
public static final int HEIGHT = 600 ;
private JButton sendButton ;
private JTextField messageField ;
private JList peopleList ;
private JTextArea viewPane ;

private static final String iconDir = "icons/";
private static final String emoticonsDir = "emoticons/";
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on problem with JList, JSplitPane and JScrollPane Or get search suggestion and latest updates.




Tagged: