jpanel

Serializing swing/awt components

…衆ロ難τιáo~ 提交于 2019-12-20 06:20:09
问题 I am trying to serialize a JPanel but everytime i get this error: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: javax.swing.GroupLayout Can you tell me, what could be the problem or what is the proper way of serializing it. What i do is pretty simple: FOR Serializing: FileOutputStream f = new FileOutputStream("myfile.dat"); ObjectOutputStream ostream = new ObjectOutputStream(f); Object object = panel; //where panel is a JPanel type object ostream

paintComponent not painting onto JPanel

﹥>﹥吖頭↗ 提交于 2019-12-20 06:07:02
问题 I am working on a homework assignment where I am supposed to make a program that allows you to paint custom shapes and lines, and move them around the screen. Originally I was using public void paint(g) to paint, but the shapes were flickering when I called repaint. Because of that I switched over to paintComponent(g) . However When I try to paint a shape nothing shows up. I believe this is because it isn't painting on top of the JPanel . The frame has 3 panels in a 3 row BorderLayout .

Parent container/panel for a CardLayout

孤人 提交于 2019-12-20 05:49:07
问题 How I can get the 'container' panel for any panel in CardLayout . That is, if a panel is a card in another 'container' panel, then how to get reference to this 'container' panel, from the card? Here's what i am doing:- public class LogInPanel extends javax.swing.JPanel implements ActionListener{ /** * Creates new form Panel2 */ private JPanel parentPanel; private CardLayout c1=null; public LogInPanel() { initComponents(); //c1=new CardLayout(); parentPanel=(JPanel)(SwingUtilities

Second row of gridbaglayout scrolling out of container

限于喜欢 提交于 2019-12-20 05:43:20
问题 I am trying to achieve a layout similar to that of a carousel. It needs to have images added horizontally with a checkbox field in the second row. I have a panel within a jscrollpane and individual images are added to the panel as labels. Please see screen shot. screenshot When I scroll the pane , the first row containing the images stays well within the panel..but if you notice the second row of checkboxes , it scrolls out of the panel. Here is the code ... JLabel lab1=new JLabel(); for (int

Go back to prior JPanel

孤街浪徒 提交于 2019-12-20 05:35:10
问题 I have inherited code and for reasons to long to explain I am required to use a null layout. I have been attempting to take what they have an navigate between JPanels. I haven't been able to figure out how. This is what I have now which compiles broken down into a SSCCE below. What I am attempting to do is add the JPanels to an ArrayList which contains a reference to previous JPanels. That way I can call a "home" JPanel from the current JPanel the user is in. As of now it goes to the previous

How to get JScrollPanes within a JScrollPane to follow parent's resizing

若如初见. 提交于 2019-12-20 04:48:44
问题 So I have a bunch of JTable s. Each JTable is inside a JScrollPane . I'm then adding each of these JScrollPane s to a JPanel . I'm then adding this JPanel to a JScrollPane then that to another JPanel with BorderLayout . The larger JScrollPane properly resizes with its parent, but each of the smaller JScrollPane s have constant height, which is larger than the window when it is small. How can I get each of the children JScrollPane s to resize with the height of the window/their parent? I've

Switching JPanels and keyListeners

半城伤御伤魂 提交于 2019-12-20 04:23:46
问题 I am developing a game, where you first get to the main screen, there are multiple selections to go, for example, Singleplayer, Twoplayer, Credits, etc. I have one big problem. If I click a button in the menu, (not JButton ) the JPanel s switch, but the keyListener is lost. The Keylistener is in the same class as the game code, which implements JPanel . I tried everything to get the Keylistener to work, but it just won't. Here is how the things are called: Main class --> Menu --> Game. I

What is the correct way to use JPanels in Netbeans?

你离开我真会死。 提交于 2019-12-20 04:23:35
问题 I'm new to Java GUI. First I created a JFrame and have added a JPanel. After that I set it as a Null Layout. Then added a label and set a background image for the frame. For my project I need to add separate 4 JPanels for this JFrame. On those JPanels I'm going to add Labels and Text boxes. I want to know whether it's correct or not to add 4 JPanels on a main JPanel? 回答1: I want to know whether it's correct or not to add 4 JPanels on a main JPanel? Sure. Most of the Java GUIs you see that are

JFrame very small using null layout

不羁岁月 提交于 2019-12-20 04:15:45
问题 Hi I am writing a simple program to display a frame. However the frame turns out real small when I type setLayout(null); But if i ignore this command, the button is always at the top center Can some one point out my error? import java.io.*; import javax.swing.*; import java.awt.event.*; import java.awt.*; class theframe { private static void create() { JFrame frame = new JFrame("FrameDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Insets insets = frame.getInsets(); frame.setSize

JLayeredPanel layout manager free moving objects

南楼画角 提交于 2019-12-20 03:53:40
问题 I have a game board, with 8 pieces that I would like to be able to move them anywhere on the jpanel. Currently, I can only do flow or grid layout, however this does not yield the desired results. The long term goal, is to be able to independently click on a piece and drag it to desired location/position. (including on top of other pieces) Any suggestions or input would be most welcome... (Thanks to Hovercraft Full Of Eels, MadProgrammer, peeskillet, Andrew Thompson for their earlier