Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: JFileChoose is huge:

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default JFileChoose is huge:

    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


  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: JFileChoose is huge:

    who did I upset? Why is no one posting anything?

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: JFileChoose is huge:

    I don't believe you've upset anyone. While someone here suggested you use MigLayout, the expertise in this forum is primarily focused on Java SE. Experience with 3rd-party libraries is less available and deep, and those who volunteer here who don't already use the 3rd-party library will likely not download it, install it into their environment, and take extra time to figure out something new they probably will rarely (if ever) use again.

    MigLayout is a good tool (or was in its day), but getting good at using it will probably be all up to you. A couple of the things I quickly became disappointed in when I ran across it a few years ago were: 1) the documentation is lousy (it grows on you but takes time), and 2) the apparent low adoption of it by others. I have used it as a lesson in the use of 3rd-party libraries since: if the library hasn't been updated recently, the documentation sucks, and no one else is using it, then it's probably not worth spending much time with. Those lessons are mine. I don't expect you to adopt them or anyone else to agree with them.

  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    219
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Re: JFileChoose is huge:

    what do you recommend?

    I would like to add the name, location of the item and the price of them item to the database. The user will select a png,jpeg file and displays it dynamically on the frame once they hit the preview button. Once they hit submit it will be placed inside the database.
    Currently I am using MCV as my design.

    This is mainly for practice but want to make my own database for my house.

    More importantly I have a internship coming up and I am do all I can to practice and wanted to apply good programming practices.

    JFileChooser is rather huge and would like it to look different. Any advice?

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: JFileChoose is huge:

    what do you recommend? . . . Any advice?
    I offered that in your earlier thread(s), largely ignored. You'll probably learn more by continuing to explore the options and tinkering with the available tools until you get the desired results.

  6. #6
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: JFileChoose is huge:

    I would guess that the way you use the layout it gives the FileChooser as big of a size as possible.
    Play around with the various options of the layout until you find a selection that suits your needs.

    When using the MigLayout I would generaly stick with adding components based on the grid. There you can set whether the row / column should grow or not, or if it grows, how big it should grow until it reaches its maximum.

Similar Threads

  1. a HUGE list of errors, and i dont know why.
    By MR bruto in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 10th, 2013, 07:10 AM
  2. Stupidly Huge Numbers?
    By sci4me in forum Java Theory & Questions
    Replies: 3
    Last Post: March 3rd, 2013, 11:51 PM
  3. Help simplifying huge nested if statement?
    By racecar333 in forum Loops & Control Statements
    Replies: 6
    Last Post: November 1st, 2011, 01:03 AM
  4. JFileChoose and FileOutputStream, nothing is being saved
    By lost in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 27th, 2010, 08:10 PM