I will attached a picture below of what the application looks like below, I also attached the code. What do you think about the code style, meaning using methods for each JPanel? In the past I just did everything in the constructor and seen an example of it done this way and really liked it.
This main issue is the positioning, and the JFileChooser is huge. How can I get it smaller using MigLayout? Or perhaps do something to it in its method.
I would also like to display the picture after it is chosen and I am having a hard time resourcing a way to do that.
package addItemBtn.Home.DataBase; import java.awt.GridLayout; import javax.swing.*; import net.miginfocom.swing.MigLayout; public class AddItemView { JFrame frame; JPanel btnPanel,descriptionPan,picturePanel,textPanel; JTextField nameBox,priceBox,locationBox; JLabel nameLbl,descriptionLbl,priceLbl,locationLbl,pictureLbl; JTextArea descriptionBox; JButton submitBtn,cancelBtn,previewBtn,browseBtn; JFileChooser fileopen; public AddItemView() { //set up frame frame = new JFrame("Add Item"); frame.setSize(750,500); frame.setLayout(new MigLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); btnPanel = new JPanel(); descriptionPan= new JPanel(); picturePanel= new JPanel(); textPanel= new JPanel(); textPanel = textBoxes(textPanel); btnPanel = bottomButtons(btnPanel); descriptionPan = descriptionPanel(descriptionPan); picturePanel = pictureArea(picturePanel); //place textFields to top left of frame frame.add(textPanel,"cell 0 1"); //place picture panel into top right of frame frame.add(picturePanel,"cell 8 1"); //place buttons on bottom of frame frame.add(btnPanel,"dock south"); //place descriptionPanel to the center of the frame frame.add(descriptionPan,"dock south"); frame.setVisible(true); } JPanel bottomButtons(JPanel panel) { submitBtn = new JButton("Submit"); cancelBtn= new JButton("Cancel"); previewBtn= new JButton("Preview"); //panel = new JPanel(); panel.setLayout(new MigLayout()); panel.add(submitBtn); panel.add(cancelBtn); panel.add(previewBtn,"wrap"); return panel; } JPanel textBoxes(JPanel panel) { nameLbl = new JLabel("Name: "); priceLbl = new JLabel("Price: "); locationLbl= new JLabel("Location: "); nameBox = new JTextField(15); priceBox= new JTextField(5); locationBox= new JTextField(15); panel.setLayout(new GridLayout(3,6)); panel.add(nameLbl); panel.add(nameBox); panel.add(priceLbl); panel.add(priceBox); panel.add(locationLbl); panel.add(locationBox); return panel; } JPanel descriptionPanel(JPanel panel) { descriptionBox = new JTextArea(15,30); JScrollPane scrollPane = new JScrollPane(descriptionBox); panel.add(scrollPane); return panel; } JPanel pictureArea(JPanel panel) { fileopen = new JFileChooser(); panel.add(fileopen); return panel; } }
Its is not letting me post the png file... Working on it right now