AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

once again, another dumb noob question

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Justin
Guest





PostPosted: Fri Nov 17, 2006 5:34 am    Post subject: once again, another dumb noob question Reply with 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....


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





PostPosted: Fri Nov 17, 2006 6:08 am    Post subject: Re: once again, another dumb noob question Reply with quote



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





PostPosted: Fri Nov 17, 2006 7:46 am    Post subject: Re: once again, another dumb noob question Reply with quote



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





PostPosted: Fri Nov 17, 2006 8:11 am    Post subject: Re: once again, another dumb noob question Reply with quote

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





PostPosted: Fri Nov 17, 2006 8:11 am    Post subject: Re: once again, another dumb noob question Reply with quote

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





PostPosted: Fri Nov 17, 2006 8:11 am    Post subject: Re: once again, another dumb noob question Reply with quote

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

Quote:
setLayout(null);


Learn layouts, and this problem should disappear.

Andrew T.
Back to top
Justin
Guest





PostPosted: Fri Nov 17, 2006 6:47 pm    Post subject: Re: once again, another dumb noob question Reply with 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.
Back to top
Thomas Weidenfeller
Guest





PostPosted: Fri Nov 17, 2006 7:12 pm    Post subject: Re: once again, another dumb noob question Reply with quote

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.

That just means you have written 30 classes for a non-portable,
non-cross-platform, non-robust GUI. Congratulations!

/Thomas
--
The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Back to top
Andrew Thompson
Guest





PostPosted: Fri Nov 17, 2006 8:15 pm    Post subject: Re: once again, another dumb noob question Reply with quote

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





PostPosted: Fri Nov 17, 2006 8:43 pm    Post subject: Re: once again, another dumb noob question Reply with 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.
Back to top
Justin
Guest





PostPosted: Fri Nov 17, 2006 8:43 pm    Post subject: Re: once again, another dumb noob question Reply with 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.
Back to top
Andrew Thompson
Guest





PostPosted: Fri Nov 17, 2006 10:42 pm    Post subject: Re: once again, another dumb noob question Reply with quote

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





PostPosted: Fri Nov 17, 2006 11:45 pm    Post subject: Re: once again, another dumb noob question Reply with quote

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





PostPosted: Sat Nov 18, 2006 5:13 am    Post subject: Re: once again, another dumb noob question Reply with quote

"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





PostPosted: Tue Nov 21, 2006 8:10 am    Post subject: Re: once again, another dumb noob question Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.