Results 1 to 3 of 3
Thread: Changing JPanel sizes
- 08-12-2009, 12:29 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 8
- Rep Power
- 0
Changing JPanel sizes
Hi to all,
Hope you all will be fine.I have a recorder for record sound, now i want to add slider to the recorder so i know for how much time i record a voice but the problem is after adding Jslider to the panel the panel sizes are disturbed and i don't know how i change the panel size. First i try to see whether something like panel.setsize() method is exist then i try to adjust by using Layouts but i was unable to fix this problem.
when you'll open the attachment you'll see four panels with four different colors.It is for easiness that for which panel i am talking about.The panel in green i want that green panel increase its height and the panel in red which include two sub panel one in blue contain Jslider and the other in yellow contain Done button shrink their heights accordingly and the buttonPanel which includes three buttons remain as it is.
Also i want slider shows 0, 1, 2 and 3.I want it also shows 1 and 2 between 0 and 3 on their respective ticks and want to add seconds ticks between 0 and 1 and so on. How can i do this
Thanks in advance.
Here is the code
Java Code:public CapturePlayback1() { setLayout(new BorderLayout()); EmptyBorder eb = new EmptyBorder(5,5,5,5); SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED); JPanel p1 = new JPanel(); p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS)); JPanel p2 = new JPanel(); p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); JPanel buttonsPanel = new JPanel(); playButton = addButton("Play", buttonsPanel, false); recordButton = addButton("Record", buttonsPanel, true); pauseButton = addButton("Pause", buttonsPanel, false); p2.add(buttonsPanel); JPanel samplingPanel = new JPanel(new BorderLayout()); samplingPanel.setBorder(new LineBorder(Color.GREEN, 2, true)); eb = new EmptyBorder(10, 20, 25, 20); samplingPanel.add(samplingGraph = new SamplingGraph()); p2.add(samplingPanel); JPanel savePanel = new JPanel(); savePanel.setBorder(new LineBorder(Color.RED, 2, true)); savePanel.setLayout(new BoxLayout(savePanel, BoxLayout.Y_AXIS)); JPanel saveTFpanel = new JPanel(); saveTFpanel.setBorder(new LineBorder(Color.BLUE, 2, true)); saveTFpanel.setLayout(new BorderLayout()); progressSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 3, 0); progressSlider.setMajorTickSpacing(3); progressSlider.setMinorTickSpacing(1); progressSlider.setPaintTicks(true); progressSlider.setPaintLabels(true); saveTFpanel.add(progressSlider); savePanel.add(saveTFpanel); JPanel saveBpanel = new JPanel(); saveBpanel.setBorder(new LineBorder(Color.yellow, 2, true)); doneButton = addButton("Done", saveBpanel, false); savePanel.add(saveBpanel); p2.add(savePanel); p1.add(p2); add(p1); }Last edited by Basit; 08-12-2009 at 12:32 PM.
-
Recommendations:
1. Please post a small compilable program that we can run and modify and that demonstrates your problem.
2. Show a picture of your current app (this has probably already been done above).
3. But also show a picture (if possible) of what you want the app to look like.
Best of luck!
-
Edit, you can best suggest the JPanel sizes to your layout via setPreferredSize as most layouts work best with this.
One way to have small hash marks between ints in your JSlider is to make your slider actually go from 0 to 30, but change the JSlider's label tabel to translate 10 to a JLabel displaying 1, 20 to a jlabel showing 2, etc...
for example -- compilable code to try out:
You'll need to translate your slider values by dividing by 10 before using them though.Java Code:import java.awt.*; import java.util.Dictionary; import java.util.Hashtable; import javax.swing.*; import javax.swing.border.*; public class CapturePlayback1 extends JPanel { private static final Dimension SAMPLING_GRAPH_SIZE = new Dimension(300, 300); private JButton playButton; private JButton recordButton; private JButton pauseButton; private JButton doneButton; public CapturePlayback1() { setLayout(new BorderLayout()); EmptyBorder eb = new EmptyBorder(5,5,5,5); SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED); JPanel p1 = new JPanel(); p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS)); JPanel p2 = new JPanel(); p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); JPanel buttonsPanel = new JPanel(); playButton = addButton("Play", buttonsPanel, false); recordButton = addButton("Record", buttonsPanel, true); pauseButton = addButton("Pause", buttonsPanel, false); p2.add(buttonsPanel); JPanel samplingPanel = new JPanel(new BorderLayout()); samplingPanel.setBorder(new LineBorder(Color.GREEN, 2, true)); eb = new EmptyBorder(10, 20, 25, 20); //samplingPanel.add(samplingGraph = new SamplingGraph()); samplingPanel.add(new JLabel("SamplingGraph", SwingConstants.CENTER)); samplingPanel.setPreferredSize(SAMPLING_GRAPH_SIZE); p2.add(samplingPanel); JPanel savePanel = new JPanel(); savePanel.setBorder(new LineBorder(Color.RED, 2, true)); savePanel.setLayout(new BoxLayout(savePanel, BoxLayout.Y_AXIS)); Dictionary<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); labelTable.put(0, new JLabel("0")); labelTable.put(10, new JLabel("1")); labelTable.put(20, new JLabel("2")); labelTable.put(30, new JLabel("3")); JPanel saveTFpanel = new JPanel(); saveTFpanel.setBorder(new LineBorder(Color.BLUE, 2, true)); saveTFpanel.setLayout(new BorderLayout()); JSlider progressSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 30, 0); progressSlider.setLabelTable(labelTable); progressSlider.setMajorTickSpacing(10); progressSlider.setMinorTickSpacing(2); progressSlider.setSnapToTicks(true); progressSlider.setPaintTicks(true); progressSlider.setPaintLabels(true); saveTFpanel.add(progressSlider); savePanel.add(saveTFpanel); JPanel saveBpanel = new JPanel(); saveBpanel.setBorder(new LineBorder(Color.yellow, 2, true)); doneButton = addButton("Done", saveBpanel, false); savePanel.add(saveBpanel); p2.add(savePanel); p1.add(p2); add(p1); } private JButton addButton(String text, JPanel panel, boolean enabled) { JButton button = new JButton(text); button.setEnabled(enabled); panel.add(button); return button; } private static void createAndShowGUI() { JFrame frame = new JFrame("FuSwing1 Application"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new CapturePlayback1()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }Last edited by Fubarable; 08-12-2009 at 06:51 PM.
Similar Threads
-
Color-changing model
By higuchi in forum New To JavaReplies: 1Last Post: 03-19-2009, 07:29 AM -
its not changing bgcolor
By javanoobita in forum Java AppletsReplies: 1Last Post: 02-21-2009, 02:29 PM -
Changing the Jframe
By Nemo1959 in forum New To JavaReplies: 13Last Post: 09-19-2008, 03:58 PM -
Dynamically changing the display
By abhiN in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 01-22-2008, 11:19 PM -
Changing icon of JOptionPane
By mew in forum New To JavaReplies: 3Last Post: 12-21-2007, 07:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks