0

I am trying to create a GUI for a small command line program. I am doing it in Jython as I am more comfortable with Python than Java.

A pear of my code looks like:

    self.f = JFrame("Demultiplex the data")
    self.f.setSize(900, 500)
    self.f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

    #Create a Text Area
    self.txtArea = JPanel(GridLayout(15,0))
    self.txtArea.setPreferredSize(Dimension(150, 150))
    self.textAreaForSheet = JTextField(30)
    self.textAreaInputForFolder = JTextField(30)
    self.textAreaOutPutFolder= JTextField(30)
    self.txtArea.add(self.textAreaForSheet)
    self.txtArea.add(self.textAreaInputForFolder)
    self.txtArea.add(self.textAreaOutPutFolder)

    #Create Buttons
    self.buttonArea = JPanel(GridLayout(15,15))
    self.buttonArea.setPreferredSize(Dimension(150, 150))
    self.sampleSheetBtn = JButton("SampleSheet", actionPerformed=self.onClickSample)
    self.runOutPutFolder = JButton("RUN Folder",actionPerformed=self.onClickRun)
    self.DemultiplexOutPutFolder = JButton("Output Folder",actionPerformed=self.onClickOut)
    self.buttonArea.add(self.sampleSheetBtn)
    self.buttonArea.add(self.runOutPutFolder)
    self.buttonArea.add(self.DemultiplexOutPutFolder)

    #Create Check Boxes
    self.CheckBox = JPanel(GridLayout(15,15))
    self.buttonArea.setPreferredSize(Dimension(150, 150))
    self.Iter1 = JCheckBox("01_0M_NY", True,)
    self.Iter2 = JCheckBox("02_0M_N", True,)
    self.Iter3 = JCheckBox("03_1M_NY", True,)
    self.Iter4 = JCheckBox("04_1M_N", True,)

    self.CheckBox.add(self.Iter1)
    self.CheckBox.add(self.Iter2)
    self.CheckBox.add(self.Iter3)
    self.CheckBox.add(self.Iter4)

    #Create a Run button "Demultiplex"
    self.ExecutePanel = JPanel()
    self.console=JTextArea(10,80)
    self.RunBtn = JButton("Demultiplex",actionPerformed= self.performDemultiplex)
    self.ExecutePanel.add(self.RunBtn)
    self.ExecutePanel.add(self.console)

    #Add everything to JFrame
    self.f.add(self.txtArea, BorderLayout.CENTER)
    self.f.add(self.buttonArea, BorderLayout.WEST)
    self.f.add(self.CheckBox, BorderLayout.EAST)
    self.f.add(self.ExecutePanel, BorderLayout.SOUTH)

But I want the console 'self.console=JTextArea(10,80)' to occupy the major area in the centre. I am a biologist and please help me.

How it Looks Now: enter image description here

gthm
  • 1,878
  • 4
  • 26
  • 37
  • You say you want to have `console` in the center, then why don’t you add it to the center? At the moment you are adding `txtArea` to the center and `ExecutePanel`, which contains your `console`, to the *south*. Btw. your constant switching between lowercase and uppercase names is horrible. – Holger Aug 13 '14 at 12:15

1 Answers1

2

For the reasons discussed here, don't use setPreferredSize(). The calculated preferred size for your components, including the JTextArea(10,80), will be correct for the platform's Look & Feel after you add the text area to the frame's BorderLayout.CENTER and pack() the enclosing Window.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045