Bsm: you should not use JLists for this situation but JComboBoxes which will have drop down lists that display correctly over the JTextArea. For e.g.
Up vote 1 down vote favorite share g+ share fb share tw.
I want to disply JList over the JTextArea but its showing it behind the JTextArea. I have attached two images to describe my problem through images. At runtime how can we set JList over the JTextArea?
JList behind JTextArea: JList over JTextArea: java swing jlist jtextarea link|improve this question edited Apr 9 '11 at 19:42Bart Kiers42.7k74272 asked Apr 9 '11 at 19:29bsm15810 87% accept rate.
1 @bsm: I think that you've got something funky going on in your code that is messing things up. Your best bet is to create and post an SSCCE (please click on the link), a small compilable, runnable program that demonstrates your best attempt at solving this. Then we can inspect your code, run it, modify it and best be able to help you fix it.
Are you mixing any AWT components with your Swing components, perhaps using a Canvas or a TextArea (instead of JTextArea) object anywhere? – Hovercraft Full Of Eels Apr 9 '11 at 19:34 I want to display the list while clicking on that button and after selecting an item from the list, list will be hidden. So for that,I have used JPanel and put JList in it as I didn't found any way to set directly visibility of JList.
I am using netbeans,so the code regarding my problem has been generated automatically after dragging and dropping components on the Frame. Thats the only reason,I have attached image here as there so many auto generated lines in the code. – bsm Apr 9 '11 at 19:42 1 @bsm: also, why use a JList and not the more appropriate JComboBox?
And to learn how to code Swing, you should avoid NetBeans code generation but rather use the Swing tutorials as a guide to help you learn to code it by hand. – Hovercraft Full Of Eels Apr 9 '11 at 19:42 I have accepted 2 answers out of 4,but don't know why its showing that I have accepted only 1. I am new here, so learning everyday and improving regarding up votes and accepting useful answers and comments.. – bsm Apr 9 '11 at 19:46 @ Hovercraft Full Of Eels..Yes I totally agree..But I am a student and I have only few days to complete a big task..I really love to work hard and learn new things but only because of less days,I am using it so that can spend remaing time in learning other problems.
I really appreciate everyone's comments and answers here. – bsm Apr 9 '11 at 19:54.
Bsm: you should not use JLists for this situation but JComboBoxes which will have drop down lists that display correctly over the JTextArea. For e.g. , import java.awt. BorderLayout; import javax.swing.
*; public class JComboAndJTextArea extends JPanel { private static final String ITEMS1 = {"one", "two", "three", "four", "five"}; private static final String ITEMS2 = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; public JComboAndJTextArea() { JPanel northPanel = new JPanel(); northPanel. Add(new JCheckBox("Reminder")); northPanel. Add(new JComboBox(ITEMS1)); northPanel.
Add(new JComboBox(ITEMS2)); setLayout(new BorderLayout()); add(northPanel, BorderLayout. NORTH); add(new JScrollPane(new JTextArea(8, 30)), BorderLayout. CENTER); } private static void createAndShowUI() { JFrame frame = new JFrame("JComboAndJTextArea"); frame.getContentPane().
Add(new JComboAndJTextArea()); frame. SetDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); frame.pack(); frame.
SetLocationRelativeTo(null); frame. SetVisible(true); } public static void main(String args) { java.awt.EventQueue. InvokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } } I also re-recommend that you put your NetBeans code generation to the side for the time being as I honestly believe that for many it hinders their ability to learn how to code in Swing.
Yes. Thanks a lot. – bsm Apr 9 '11 at 20:11 @bsm: you're welcome.
Good luck with your project! – Hovercraft Full Of Eels Apr 9 '11 at 20:31.
I would think that default behaviour is to show combo content over other components, thus you have it this way. The only suggestion that I would think of at the moment is to use layered pane. You could check to which layer the part of combo box with options is added.
Then add the list to one above. Tutorial about LayeredPane download.oracle.com/javase/tutorial/uisw... From this description of RootPane I think the options of combobox must be shown on popup layer download.oracle.com/javase/tutorial/uisw... Good luck, Boro.
– Hovercraft Full Of Eels Apr 9 '11 at 19:40 1 Good point my bad. I thought that he is after actually this behaviour and that the JList is at the bottom and combo at the top. Sorry, my bad.
Hovercraft Full Of Eels you are tight the code is a must to see. – Boro Apr 9 '11 at 19:45 1 Even though,I also agree with Hovercraft Full Of Eels' point, Thanks Boro for sharing useful links. – bsm Apr 9 '11 at 20:04.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.