This is why I dont use layout managers

J

Justin

heres the code i am using...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.font.*;
import java.text.Collator;
import javax.swing.event.*;
import java.util.Date;
import java.text.DateFormat;

class ExamKnee2 extends JDialog{

JLabel textKneeSocietyScore;
JButton btnOK;

ExamModuleFollowups followup;
ExamModuleExamKnee examKnee;
ExamModuleActivity activity;
ExamModulePainGrade painGrade;
ExamModuleSymptoms symptoms;

Color bgColor = Color.YELLOW;

final int WIDTH = 830;

AccessConnection dataConnection = new AccessConnection();

public String sSN, side;

JPanel panel;
JScrollPane scroller;

public ExamKnee2(String stringSide, String stringSSN, String
timePain) {

side = stringSide;
sSN = stringSSN;

setModal(true);
Container pane = this.getContentPane();
this.setAlwaysOnTop(true);
pane.setLayout(new BorderLayout());
//pane.setLayout(null);

setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setBounds(300,0,WIDTH,600);

addWidgets();

setVisible(true);
validate();

}

public void addWidgets(){
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setSize(400, 1000);

JLabel testing = new JLabel("testing1");
panel.add(testing, BorderLayout.PAGE_START);

JLabel testing2 = new JLabel("testing2");
panel.add(testing, BorderLayout.CENTER);

JLabel testing3 = new JLabel("testing3");
panel.add(testing2, BorderLayout.PAGE_END);

scroller = new JScrollPane(panel);
scroller.setSize(100,100);
add(scroller, BorderLayout.LINE_START);

}

public static void main(String args[]){
ExamKnee2 examKnee = new ExamKnee2("Right", "123-45-6789", "2
weeks");
}
}


All I am trying to do is get the scroll pane to scroll vertically.
Will not do it. This is really pissing me off. According to the java
tutorial (found here
http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html)
the "testing" labels should be displayed horizontally. Secondly, I
should be able to scroll around to view the 3rd testing label but I
cant. I know theres more problems but im a lil piissed off right now
becuase this isnt working. please help...
 
A

A. Bolmarcich

heres the code i am using...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.font.*;
import java.text.Collator;
import javax.swing.event.*;
import java.util.Date;
import java.text.DateFormat;

class ExamKnee2 extends JDialog{

JLabel textKneeSocietyScore;
JButton btnOK;

ExamModuleFollowups followup;
ExamModuleExamKnee examKnee;
ExamModuleActivity activity;
ExamModulePainGrade painGrade;
ExamModuleSymptoms symptoms;

Color bgColor = Color.YELLOW;

final int WIDTH = 830;

AccessConnection dataConnection = new AccessConnection();

public String sSN, side;

JPanel panel;
JScrollPane scroller;

public ExamKnee2(String stringSide, String stringSSN, String
timePain) {

side = stringSide;
sSN = stringSSN;

setModal(true);
Container pane = this.getContentPane();
this.setAlwaysOnTop(true);
pane.setLayout(new BorderLayout());
//pane.setLayout(null);

setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setBounds(300,0,WIDTH,600);

addWidgets();

setVisible(true);
validate();

}

public void addWidgets(){
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setSize(400, 1000);

JLabel testing = new JLabel("testing1");
panel.add(testing, BorderLayout.PAGE_START);

JLabel testing2 = new JLabel("testing2");
panel.add(testing, BorderLayout.CENTER);

Instead of the above line, did you intend to write

panel.add(testing2, BorderLayout.CENTER);
JLabel testing3 = new JLabel("testing3");
panel.add(testing2, BorderLayout.PAGE_END);

Instead of the above line, did you intend to write

panel.add(testing3, BorderLayout.PAGE_END);
scroller = new JScrollPane(panel);
scroller.setSize(100,100);
add(scroller, BorderLayout.LINE_START);

}

public static void main(String args[]){
ExamKnee2 examKnee = new ExamKnee2("Right", "123-45-6789", "2
weeks");
}
}


All I am trying to do is get the scroll pane to scroll vertically.
Will not do it. This is really pissing me off. According to the java
tutorial (found here
http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html)
the "testing" labels should be displayed horizontally. Secondly, I
should be able to scroll around to view the 3rd testing label but I
cant. I know theres more problems but im a lil piissed off right now
becuase this isnt working. please help...

What may be really pissing you off is that Java does what you wrote,
not what you meant to write.

With the code as written, the "testing" labels should be displayed
vertically (once you add all three instead of adding and re-adding
"testing" and then adding "testing2"). To get the scroll pane to
have a vertical scroll bar, you have to reduce the height of the
window so that there is not enough height to show all the "testing"
labels at the same time.

Also, you may have meant to add the scroll pane to the CENTER instead
of to the LINE_START.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top