11/25/2023 0 Comments Java flowlayout example![]() ![]() And I apologise if the solutions is on this site somewhere. Make heading bold - find out if there's a better way to do thisįont boldFont = new Font(font.getFontName(), Font.BOLD, font.getSize()) Īdd( tbdPanel, BorderLayout.CENTER ) // Add TBD Panel to CENTER of JFrame JLabel dets = new JLabel("The Body of the text goes here") JPanel tbdItem = new JPanel( new FlowLayout() ) // JPanel tbdPanel = new JPanel( new FlowLayout() ) JButton deleteTask = new JButton("Delete Task") ĭeleteTask.addActionListener( new DeleteTask() ) ĭtPreferredSize(new Dimension(130, 40)) JButton editTask = new JButton("Edit Task") ĮditTask.addActionListener( new EditTask() ) ĮtPreferredSize(new Dimension(130, 40)) NewTask.addActionListener( new NewTask() ) JButton newTask = new JButton("New Task") GetContentPane().setBackground(Color.LIGHT_GRAY) ītBackground(Color.LIGHT_GRAY) SetDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ) SetLocationRelativeTo(null) //Center window on open I really don't understand why it isn't working as the JPanel I'm inserting into is a FlowLayout(): super("To Be Done") ![]() If you check my code bellow, I believe I have correctly used the FlowLayout() layout manager, but in actuality the output looks like it's ignoring my JPanel and is instead using the layout manager of my JFrame? An image of (wrong) output here: I've searched around and tried a solution here (the solution using GridLayout()) but that didn't work either. I am stuck on trying to get my two JLabels: heading & dets, to appear underneath each other in the JPanel tbdItem. However, diving into Swing, I have hit a blockade (perhaps biting off a little too much at once). Ultimately, this is just a project to add to my portfolio of code and to reinforce what I learned in Data Structures & Algorithms over the semester. I'm a second year CS student (on winter break) and I'm trying to teach myself Swing. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |