So i have two classes:
public class TimeServer extends JPanel implements TimeVariables
{
public TimeServer()
{
JTextArea serverLog = new JTextArea();
// Create a scroll pane to hold text area
JScrollPane scrollPane = new JScrollPane(serverLog);
JPanel serverWin = new JPanel();
serverWin.add(scrollPane);
}
and another class that has:
private JPanel mainWin = new JPanel();
private JPanel gridArea = new JPanel(); //hold cells
TimeServer serverWin = new TimeServer();
public class TimClient extends JFrame implements Runnable, TimeVariables
{
his.add(mainWin, BorderLayout.CENTER);
mainWin.setLayout(new BorderLayout());
// mainWin.setLayout(new GridLayout(1,2));
//Create Grid
gridArea.setLayout(new GridLayout(10, 10, 2, 2));
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
gridArea.add(cell[i][j] = new Cell(i, j, this));
gridArea.setBorder(new LineBorder(Color.black, 1));
jlblTitle.setHorizontalAlignment(JLabel.CENTER);
jlblTitle.setFont(new Font("SansSerif", Font.BOLD, 16));
jlblTitle.setBorder(new LineBorder(Color.black, 1));
jlblStatus.setBorder(new LineBorder(Color.black, 1));
mainWin.add(gridArea, BorderLayout.CENTER);
mainWin.add(serverWin, BorderLayout.PAGE_END);
// Place the panel and the labels to the frame
setLayout(new BorderLayout()); // implicit anyway
add(jlblTitle, BorderLayout.NORTH);
add(mainWin, BorderLayout.CENTER);
add(jlblStatus, BorderLayout.SOUTH);
}
public static void main(String[] args) {
// Create a frame
TimClient frame = new TimClient("Time Client");
//frame.getContentPane().add(BorderLayout)
// Display the frame
frame.setSize(620, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
all i want to do is keep the server log and grid in the JPanel next to one another, could you explain how?
also how do i add the JPanel in the server class to the one in client?
Here's a sketch of how i'd like it to look:
Your problems above appear to stem from a bad Swing code practice, one that seems to be reinforced by Swing code generators (although I'm not sure if you're currently using this tool) and the official Swing tutorials, and that is:
So I suggest that you do just this:
If you've done a good job of separated your GUI code from your logic code, then it should be easy to re-write the GUI code while keeping your same logic (or "model") code.
Edit 2
Regarding your changed question where now the first class extends JPanel, simply add that JPanel to your JFrame in the BorderLayout.LINE_END end (also known as BorderLayout.EAST) position.