0
textPane = new JTextPane();
		textPane.setBounds(337, 33, 290, 198);
		textPane.setBackground(Color.LIGHT_GRAY);
		textPane.setEditable(false);
		textPane.setLayout(new GridLayout());
		JScrollPane scrollPane = new JScrollPane(textPane);
		scrollPane.setBounds(337, 33, 290, 198);
		add(scrollPane);
		
searchButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				List<MainManagement> sList = new ArrayList<MainManagement>();
				MainMngDao mmd = new MainMngDao();
				sList = mmd.search();
				for(int i = 0; i < sList.size(); i++) {
					textPane.setText(sList.get(i).toString());
				}
			}
		});

this is just part of the codes
i used textpane and it can show everything in the list.why?
please give me a pointer
no matter what way i do it , iterator or for() loop, i can acheive it...

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by mKorbel
0

Simple

for(int i = 0; i < sList.size(); i++) {
    textPane.setText(sList.get(i).toString());
}

Any previously added text is overwritten by new setText() in your loop.
Simplest workaround put whole list in StringBuilder and get one string that is added to JTextPane.
Advanced, create StyledDocument


PS: This is not 24/7 answer service just for you. We answer when we can and when we have time, not when you demand.

Edited by peter_budo: n/a

0

hmmm

textPane.setText(textPane.getText() + "\LineSepartor" + sList.get(i).toString());

That is functional, but it is much of get & set for graphical component. I would prefer to provide text pane in this case with single set

0

bump,

now is corresponding with topic

scrollPane.setVerticalScrollBarPolicy(               JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.