I'm developping a Java application.
I created this interface with MockupScreens. Please look at these pictures.
At first time, there's only one element, the user have to enter informations (title and description) then he starts adding elements as he needs. He can edit elemnt infomrations at any time. He can too delete or change the order of this elements ...
How can I do to create something like the pictures up?????
Thanks in advance. Best regards,
I know these parts in Java Swing. My problem is how to insert this block of buttons dynamically.
I get an idea, I must put JButtons on a JPanel then manipulate the JPanel by adding, removing and reodering... So a Grid Layout will be efficient to add each panel after each one, but thinking on reordering the order will be so hard ...
Any suggestions please. :)
After searching, I get an idea:
Let us put these JButtons in a JPanel called btnsUnit, then manipulate it by adding, removing and reodering... So a GridLayout will be efficient to add each JPanel after each one ..
Thats why I created a new JPanel which will contain an unknown number of ListbtnsUnit JPanel, I fixed 10 as the max number.
I'm just doing these steps when you reply me. I didn't arrived to add btnsUnit JPanel in ListbtnsUnit JPanel.
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
public class setupDeviceList extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
setupDeviceList frame = new setupDeviceList();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public setupDeviceList() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 742, 335);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
final JPanel ListbtnsUnit = new JPanel();
ListbtnsUnit.setBackground(Color.RED);
ListbtnsUnit.setBounds(55, 56, 243, 191);
contentPane.add(ListbtnsUnit);
ListbtnsUnit.setLayout(new GridLayout(10, 0));
final JButton btnAdd = new JButton("Add");
btnAdd.setBounds(161, 11, 56, 23);
btnAdd.setVisible(true);
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
final JPanel btnsUnit = new JPanel();
btnsUnit.setBounds(343, 71, 243, 147);
contentPane.add(btnsUnit);
btnsUnit.setBackground(Color.ORANGE);
btnsUnit.setLayout(null);
btnsUnit.add(btnAdd);
ListbtnsUnit.add(btnsUnit);
ListbtnsUnit.revalidate();
ListbtnsUnit.repaint();
}
});
}
}
Please can you help me in this code. I need just the first push to go on.
but thinking on reordering the order will be so hard ...
In your ActionListener for the button:
Nice images :-)
You need these parts, if you want to do this in Swing:
Look at these, start to code, and then come back if you have concrete problems. Good luck!
I think you are using a wrong idiom here. What you are trying to accomplish is usually done using JList (scrollable list of items). This way you need just one set of operations such as reorder, add and delete, next to the JList. Operations should operate on selected item in JList (otherwise they should be disabled)
Your interface may look sort of like
The idiom you're currently using is mostly done on web pages. Desktop UIs, (especially Swing) are much richer.
You can find more about how to use JList at http://download.oracle.com/javase/tutorial/uiswing/components/list.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With