 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Justin Guest
|
Posted: Fri Nov 17, 2006 5:34 am Post subject: once again, another dumb noob question |
|
|
I have a class that extends JPanel. In it, I have a JScrollPane.
Within that JScrollPane is a JList. I know its probably something
stupid, but I can't for the life of me figure out why the JList will
not display in the JScrollPane. Any help is appreciated....
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.*;
public class ORNote extends JPanel{
protected JList assistantsList;
protected DefaultListModel assistantsDLM;
protected JScrollPane assistantsScroller;
protected String sSN;
protected int dxID, prID;
protected int WIDTH = 381;
public ORNote(String stringSSN, int intDxID, int intPrID) {
sSN = stringSSN;
prID = intPrID;
dxID = intDxID;
setLayout(null);
setSize(WIDTH, 100);
Dimension prefSize = new Dimension();
prefSize.setSize(WIDTH,200);
setPreferredSize(prefSize);
Border blackline = BorderFactory.createLineBorder(Color.black);
setBorder(blackline);
addWidgets();
validate();
}
protected void addWidgets(){
assistantsDLM = new DefaultListModel();
assistantsList = new JList(assistantsDLM);
assistantsScroller = new JScrollPane(assistantsList);
assistantsDLM.addElement("TEsting");
add(assistantsScroller);
assistantsScroller.setBounds(80, 30, 290, 50);
assistantsScroller.add(assistantsList);
assistantsScroller.setViewportView(assistantsList);
assistantsScroller.revalidate();
}
} |
|
| Back to top |
|
 |
Justin Guest
|
Posted: Fri Nov 17, 2006 6:08 am Post subject: Re: once again, another dumb noob question |
|
|
I've been playing with that class some more, and theres definatly
something wrong with it. When I add a JComboBox, the button on the
JComboBox does not show up. No idea what. |
|
| Back to top |
|
 |
Michael Dunn Guest
|
Posted: Fri Nov 17, 2006 7:46 am Post subject: Re: once again, another dumb noob question |
|
|
Justin wrote:
| Quote: | I have a class that extends JPanel. In it, I have a JScrollPane.
Within that JScrollPane is a JList. I know its probably something
stupid, but I can't for the life of me figure out why the JList will
not display in the JScrollPane. Any help is appreciated....
code snipped |
if you mean the scrollbar does not appear, that is because
the size of the JList is smaller that that of the scrollpane
try changing this
assistantsDLM.addElement("TEsting);
to
for(int x = 0; x < 10; x++){
assistantsDLM.addElement("TEsting "+x);
} |
|
| Back to top |
|
 |
Justin Guest
|
Posted: Fri Nov 17, 2006 8:11 am Post subject: Re: once again, another dumb noob question |
|
|
nope, i mean the JList doesnt show up. For some reason, its as if the
JList wasnt even added to the ScrollPane |
|
| Back to top |
|
 |
Justin Guest
|
Posted: Fri Nov 17, 2006 8:11 am Post subject: Re: once again, another dumb noob question |
|
|
nope, i mean the JList doesnt show up. For some reason, its as if the
JList wasnt even added to the ScrollPane |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri Nov 17, 2006 8:11 am Post subject: Re: once again, another dumb noob question |
|
|
Justin wrote:
| Quote: | I have a class that extends JPanel. In it, I have a JScrollPane.
Within that JScrollPane is a JList. I know its probably something
stupid, but I can't for the life of me figure out why the JList will
not display in the JScrollPane. Any help is appreciated....
|
The code breaks right, ...here
Learn layouts, and this problem should disappear.
Andrew T. |
|
| Back to top |
|
 |
Justin Guest
|
Posted: Fri Nov 17, 2006 6:47 pm Post subject: Re: once again, another dumb noob question |
|
|
I definatly dont think thats where the problem resides as I have about
30 other classes with no layout manager. I dont think there is a
layout manager that will meet my design needs for the GUI. |
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri Nov 17, 2006 8:15 pm Post subject: Re: once again, another dumb noob question |
|
|
Justin wrote:
| Quote: | I definatly dont think thats where the problem resides as I have about
30 other classes with no layout manager. I dont think there is a
layout manager that will meet my design needs for the GUI.
|
You are wrong.
1) Nested layout*s* are often the answer to that
layout that 'no layout' (singular) can do.
2) You (think you have*) the logic to layout the GUI,
so wrap that logic in a class and extend LM2(?) and
voila.. you have a *layout*.
(* + what Thomas said)
Andrew T. |
|
| Back to top |
|
 |
Justin Guest
|
Posted: Fri Nov 17, 2006 8:43 pm Post subject: Re: once again, another dumb noob question |
|
|
ok, well, regardless of what layout manager I use (I will be in control
of the hardware that the program is run on) why does the JList not
show up? I've been playing with this for 5-6 hours and cannot get it
to show. |
|
| Back to top |
|
 |
Justin Guest
|
Posted: Fri Nov 17, 2006 8:43 pm Post subject: Re: once again, another dumb noob question |
|
|
ok, well, regardless of what layout manager I use (I will be in control
of the hardware that the program is run on) why does the JList not
show up? I've been playing with this for 5-6 hours and cannot get it
to show. And I have tried layout managers, and they dont have an
affect. |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri Nov 17, 2006 10:42 pm Post subject: Re: once again, another dumb noob question |
|
|
Justin wrote:
| Quote: | ok, well, regardless of what layout manager I use (I will be in control
of the hardware that the program is run on) why does the JList not
show up? I've been playing with this for 5-6 hours and cannot get it
to show.
|
Took me ten minutes to make it show up
using a BorderLayout - most of that time
was spent turning it into an SSCCE and
deciding what to leave the same.
<sscce>
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.*;
public class ORNote extends JPanel{
protected JList assistantsList;
protected DefaultListModel assistantsDLM;
protected JScrollPane assistantsScroller;
protected String sSN;
protected int dxID, prID;
protected int WIDTH = 381;
public ORNote(String stringSSN, int intDxID, int intPrID) {
sSN = stringSSN;
prID = intPrID;
dxID = intDxID;
// layout!
setLayout(new BorderLayout());
Border blackline = BorderFactory.createLineBorder(Color.black);
setBorder(blackline);
addWidgets();
}
protected void addWidgets(){
assistantsDLM = new DefaultListModel();
assistantsDLM.addElement("Testing");
for (int ii=0; ii<20; ii++) {
assistantsDLM.addElement(sSN + ": " + (ii+1));
}
assistantsList = new JList(assistantsDLM);
assistantsScroller = new JScrollPane(assistantsList);
add(assistantsScroller, BorderLayout.CENTER);
}
public static void main(String[] args) {
JFrame f = new JFrame("Layout");
f.add( new ORNote("Hi!",1,2) );
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
}
</sscce>
| Quote: | ...And I have tried layout managers, and they dont have an
affect.
|
I think now comes the part where you complain..
'but this is not how I want it set out!'
Andrew T. |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Fri Nov 17, 2006 11:45 pm Post subject: Re: once again, another dumb noob question |
|
|
Justin wrote:
| Quote: | ok, well, regardless of what layout manager I use (I will be in control
of the hardware that the program is run on) why does the JList not
show up? I've been playing with this for 5-6 hours and cannot get it
to show. And I have tried layout managers, and they dont have an
affect.
|
You really should use a layout manager but anyway to get you going
change your constructor to this:
public ORNote(String stringSSN, int intDxID, int intPrID)
{
// Create and set up the window.
JFrame jframe = new JFrame("test");
// Make sure we have nice window decorations.
jframe.setDefaultLookAndFeelDecorated(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setOpaque(true); //content panes must be opaque
jframe.setContentPane(this);
setLayout(null);
setSize(WIDTH, 100);
Dimension prefSize = new Dimension();
prefSize.setSize(WIDTH, 200);
setPreferredSize(prefSize);
Border blackline = BorderFactory.createLineBorder(Color.black);
setBorder(blackline);
addWidgets();
//Display the window.
jframe.pack();
jframe.setVisible(true);
}
--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
______________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-) |
|
| Back to top |
|
 |
Michael Dunn Guest
|
Posted: Sat Nov 18, 2006 5:13 am Post subject: Re: once again, another dumb noob question |
|
|
"Justin" <justin.lottes (AT) gmail (DOT) com> wrote in message
news:1163734029.054703.4930 (AT) k70g2000cwa (DOT) googlegroups.com...
| Quote: | nope, i mean the JList doesnt show up. For some reason, its as if the
JList wasnt even added to the ScrollPane
|
shows fine for me (winxp 1.5.0_05)
I now understand your post about the comboBox.
I've seen similar issues, mainly with optionPanes, solved by
reducing the pc's hardware acceleration |
|
| Back to top |
|
 |
Justin Guest
|
Posted: Tue Nov 21, 2006 8:10 am Post subject: Re: once again, another dumb noob question |
|
|
Michael Dunn wrote:
| Quote: | "Justin" <justin.lottes (AT) gmail (DOT) com> wrote in message
news:1163734029.054703.4930 (AT) k70g2000cwa (DOT) googlegroups.com...
nope, i mean the JList doesnt show up. For some reason, its as if the
JList wasnt even added to the ScrollPane
shows fine for me (winxp 1.5.0_05)
I now understand your post about the comboBox.
I've seen similar issues, mainly with optionPanes, solved by
reducing the pc's hardware acceleration
|
Thank you, I ended up trashing the class and starting from scratch.
That fixed the problem even though it was the exact same code. And
thanks all for the advice on using layouts. lol, thats going to be
resolved in version 2.0. haha. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|