Skip to main content

Resize JFrame

1 reply [Last post]
mikh
Offline
Joined: 2009-05-15

Hello,

I'm having another problem with my not so dear friend = swing programming.

I have a JFrame, to which I add a JPanel. The paintComponent() method inside JPanel, simply displays a text in the panel.
When I "resize" / "minimize then maximize" the frame, my panel doesn't get displayed.

I don't know if I have to call any repaint() / validate () / update() methods (they really get me confused) or if I'm missing anything else.

Thank you!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mikh
Offline
Joined: 2009-05-15

I've posted my code.
[code]DisasterSelectPane[/code] is also a JPanel, which holds some buttons and text boxes, but this one is correctly displayed at any time.
[code]Grid[/code] is the one I'm having problem with.

Don't know if it helps, but after the resizing of the frame, the [code]Grid[/code] disappears and the [code]DisasterSelectPane[/code] appears is shifted up in the [code]MainWindow[/code].

[code]
public class MainWindow extends JFrame
{

private static MainWindow mainWindow;
private Grid grid;
private DisasterSelectPane disasterSelectPane;

private void initComponents()
{
//mainWindowScrollPane = new javax.swing.JScrollPane(new Grid(444, 1134));
this.grid = UIAgent.grid;
//mainWindowScrollPane = new JScrollPane(this.grid);
mainWindowScrollPane = new JPanel();
mainWindowScrollPane.add(this.grid);
mainWindowScrollPane.setName("mainWindowScrollPane"); // NOI18N

this.disasterSelectPane = new DisasterSelectPane();
mainDisasterPane = new JPanel();
mainDisasterPane.setName("mainDisasterPane");

setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);

layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(this.grid, GroupLayout.DEFAULT_SIZE, 1134, Short.MAX_VALUE)
//.addComponent(mainDisasterPane, GroupLayout.DEFAULT_SIZE, 113, GroupLayout.DEFAULT_SIZE)
.addComponent(this.disasterSelectPane, GroupLayout.DEFAULT_SIZE, 1134, GroupLayout.DEFAULT_SIZE)
)
.addContainerGap())
);

layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGap(18, 18, 18)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(this.grid, GroupLayout.PREFERRED_SIZE, 444, GroupLayout.PREFERRED_SIZE)
//.addComponent(mainDisasterPane, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addComponent(this.disasterSelectPane, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
.addContainerGap(69, Short.MAX_VALUE))
);

pack();
}//
}

public class Grid extends JPanel
{
public static final int GRID_CELL_DIM = 20;

private int lines;
private int columns;
//private Map map;

public Grid(int lines, int columns)
{
this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
this.lines = lines;
this.columns = columns;
//this.map = new Map(this.lines, this.columns);
}

public void paintComponent(Graphics g)
{
super.paintComponent(g);
}

}
[/code]