Reputation: 527
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.*;
public class FileCutter
{
public static void main(String[] args)
{
CutterWindow cw = new CutterWindow();
cw.setResizable(false);
cw.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cw.setVisible(true);
}
}
class CutterWindow extends JFrame
{
private JTabbedPane tabbedPane = new JTabbedPane();
public static final int DEFAULT_WIDTH = 470;
public static final int DEFAULT_HEIGHT = 480;
public CutterWindow()
{
this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
tabbedPane.add("File Cut",new FileCutPanel());
this.add(tabbedPane);
}
}
class FileCutPanel extends JPanel
{
private JLabel lblFileName = new JLabel("File Name:");
private JTextField txtFileName = new JTextField();
private JLabel lblFileSize = new JLabel("File Size:");
private JTextField txtFileSize = new JTextField();
private JButton btnViewFiles = new JButton("...");
private JPanel panelSelectOperatingFile = new JPanel();
public FileCutPanel()
{
panelSelectOperatingFile.setLayout(new FlowLayout());
panelSelectOperatingFile.add(lblFileName);
txtFileName.setColumns(20);
txtFileName.setEditable(false);
panelSelectOperatingFile.add(txtFileName);
panelSelectOperatingFile.add(btnViewFiles);
panelSelectOperatingFile.add(lblFileSize);
panelSelectOperatingFile.add(txtFileSize);
txtFileSize.setColumns(20);
txtFileSize.setEditable(false);
this.add(panelSelectOperatingFile);
}
}
the result is that the five component in the panelSelectOperatingFile Panel are in the same line and beyond the width of the window. and i know that the default layout of the JPanel is flowlayout
, i expected that the components will be put in the next line when there is no space in the previous line. and i try to figure out the problem, but i can't
Upvotes: 1
Views: 547
Reputation: 5735
Do not use the panelSelectOperatingFile
panel. Just add your components to the JPanel
you are extending.
You can't nest FlowLayouts. Here is why:
Upvotes: 2