jpanel

How do I disable a JPanel so that it can't change size in Java

﹥>﹥吖頭↗ 提交于 2019-12-10 05:50:00
问题 I have several JPanels in a layout and whenever I change the size of the JFrame manually with my mouse, it stretches the JPanels and makes it look messy. Is there a way to disable this? 回答1: JPanel is not resizable by the user. If you are referring to JFrame, you can use yourFrame.setResizable(false); 回答2: It's all about the LayoutManager you are using. Some LayoutManagers like BorderLayout always give extra space to children added in the center position. However, north, south, east, and west

placing a transparent JPanel on top of another JPanel not working

狂风中的少年 提交于 2019-12-10 02:15:45
问题 I am trying to place a JPanel on top of another JPanel which contains a JTextArea and a button and i want to the upper apnel to be transparent. I have tried it by making the setOpaque(false) of the upper panel. but it is not working. Can anyone help me to get through this? Thanks in advance! public class JpanelTest extends JPanel { public JpanelTest() { super(); onInit(); } private void onInit() { setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout());

Java swing - displaying multiple images dynamically on JPanel

纵饮孤独 提交于 2019-12-10 00:16:37
问题 I have searched many places to add and display images dynamically on JPanel but couldn't get proper help. Basically I have JPanel on which I have to display many images vertically but it should be dynamic. for(int i=0;i<macthedImages.length;i++) { JLabel jLabel = new JLabel(new ImageIcon(macthedImages[i])); searchResultPanel.add(jLabel); } macthedImages is an array of bufferedImages searchResultPanel is JPanel 回答1: If you want to show all images at same time then use GridLayout but you have

Layers overriding each other in GUI using JPanel

大城市里の小女人 提交于 2019-12-10 00:16:35
问题 I am having trouble making the layout of a simple Calculator. What is happening is that everything appears fine except that my subtract button stays as the background and I have to guess where my other buttons are to be able to click them. When I click them I am able to see them until I unclick them. is there anyway to fix this? I'm not posting the math algorithm a it is not needed for this question. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GUIcalc

Add a JFreeChart in to JPanel

寵の児 提交于 2019-12-09 02:36:25
问题 if i have a my Jpanel and a my JFreeChart. How can I add this Chart in to the JPanel? XYSeries series = new XYSeries("XYGraph"); series.add(1, 1); series.add(1, 2); series.add(2, 1); series.add(3, 9); series.add(4, 10); // Add the series to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart( "XY Chart", // Title "x-axis", // x-axis Label "y-axis", // y-axis Label dataset, //

Creating a Count Up timer to Break in java

浪子不回头ぞ 提交于 2019-12-09 00:55:05
问题 I'm trying to implement a timer based scoring system for a puzzle application i am writing. Can someone provide me with an example case of creating a JLabel or Panel in swing, containing a visibly counting timer (in seconds from 0), which stops, on a call from a method. And returns its value. Example: hrs:mins:seconds [00:00:00] [00:00:01] .. etc.. overwriting the previous entry. Thanks EDIT: this is an adaptation of the example code linked by trashgod: ClockExample, which uses simple if

JPanels don't completely stretch to occupy the available space

落爺英雄遲暮 提交于 2019-12-08 22:13:05
问题 I have a panel where I place several mini-panels, side-by-side, with different sizes and colors, and they should occupy the entire parent panel (horizontally). For this I use BorderLayout (for the parent panel), and BoxLayout for a sub-panel where I place all the mini-panels (see code below). It does work and behave correctly uppon resizing and everything. However, as the number of mini-panels becomes larger, a strange behaviour occurs: empty space appears at the end of the parent panel. I

Java Swing: JButton creates new JTextField(s)

自作多情 提交于 2019-12-08 21:03:34
Hello :) I am beginner in Java Swing and I can't google solution for my problem. I have a JPanel and want to add JTextField(s) dynamically after pressing a JButton. And how can I getText() from them later? My code, commented part isn't working properly. Variable 'counter' counts how many fields I have in panel. public class AppPanel extends JPanel { private JTextField tfData[]; private JButton btAdd; private int counter = 1; public AppPanel() { setLayout(null); //tfData[counter] = new JTextField(); //tfData[counter-1].setBounds(20, 20, 250, 20); //add(tfData[counter-1]); btAdd = new JButton(

Clear window from drawing objects

喜欢而已 提交于 2019-12-08 19:38:32
I have 4 classes: Draw, Rectangle (extends Draw), FreeHand (extends Draw) and a test class. I add rectangles and lines drawn by free hand to an arrayList. I have a menubar with choices Back and Clear. Back removes the last drawn object. It is done by removing the last object in the arraylist. Clear clears the windows. It is done by clear the arraylist from all items. Now to my problem: The window does not clear. I don't know how to write the code to make it repaint properly so that the items removes from the window. Can you please help me with how the code for this would look like, and where I

Reason for calling setEnabled(false) in JPanel

末鹿安然 提交于 2019-12-08 18:06:30
问题 I am working on Swing for a while now but never had a situation in practice when I had to call setEnabled(false) in JPanel . Still, I see such code sometimes in some sophisticated gui. But I really don't undarstand why someone wants to use it? So, please give me some examples of real life common situations when you need to use setEnabled(false) on JPanel . Also in javadoc it says: Disabling a component does not disable its children. actually I had a bug because table inside disabled JPanel