JList Moving Lists Program












0















I don't know where I'm going wrong but here's my code and I'm facing this error.
Basically I was watching Bucky Roberts' Tutorial on moving lists program and I'm stumbling over this error.



Note: .Multiple_Selection_List.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Multiple_Selection_List extends JFrame
{
private JList leftList;
private JList rightList;
private JButton moveButton;
private DefaultListModel model;
private DefaultListModel model2;

public Multiple_Selection_List()
{
super("Multiple Selection List");
setLayout(new FlowLayout());

model=new DefaultListModel();
model.addElement("Random");

model2 = new DefaultListModel();
model2.addElement("Random");

leftList = new JList(model);
leftList.setVisibleRowCount(3);
leftList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(leftList));

moveButton = new JButton("Move to right ------------->");
moveButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
rightList.setListData(leftList.getSelectedValuesList().toArray());
}
}
);

add(moveButton);

rightList=new JList(model2);
rightList.setVisibleRowCount(3);
rightList.setFixedCellWidth(100);
rightList.setFixedCellHeight(15);
rightList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(rightList));
}
}









share|improve this question




















  • 2





    This is actually a warning and not an error, so you should still be able to run it. Have you compiled with this flag and gotten further details?

    – Joe C
    Nov 25 '18 at 12:17













  • I don,t actually know how to compile it further.. Do you mind if you could help me with that?

    – Varun Khatri
    Nov 25 '18 at 16:27






  • 1





    javac -Xlint:unchecked Multiple_Selection_List.java

    – Joe C
    Nov 25 '18 at 17:11
















0















I don't know where I'm going wrong but here's my code and I'm facing this error.
Basically I was watching Bucky Roberts' Tutorial on moving lists program and I'm stumbling over this error.



Note: .Multiple_Selection_List.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Multiple_Selection_List extends JFrame
{
private JList leftList;
private JList rightList;
private JButton moveButton;
private DefaultListModel model;
private DefaultListModel model2;

public Multiple_Selection_List()
{
super("Multiple Selection List");
setLayout(new FlowLayout());

model=new DefaultListModel();
model.addElement("Random");

model2 = new DefaultListModel();
model2.addElement("Random");

leftList = new JList(model);
leftList.setVisibleRowCount(3);
leftList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(leftList));

moveButton = new JButton("Move to right ------------->");
moveButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
rightList.setListData(leftList.getSelectedValuesList().toArray());
}
}
);

add(moveButton);

rightList=new JList(model2);
rightList.setVisibleRowCount(3);
rightList.setFixedCellWidth(100);
rightList.setFixedCellHeight(15);
rightList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(rightList));
}
}









share|improve this question




















  • 2





    This is actually a warning and not an error, so you should still be able to run it. Have you compiled with this flag and gotten further details?

    – Joe C
    Nov 25 '18 at 12:17













  • I don,t actually know how to compile it further.. Do you mind if you could help me with that?

    – Varun Khatri
    Nov 25 '18 at 16:27






  • 1





    javac -Xlint:unchecked Multiple_Selection_List.java

    – Joe C
    Nov 25 '18 at 17:11














0












0








0








I don't know where I'm going wrong but here's my code and I'm facing this error.
Basically I was watching Bucky Roberts' Tutorial on moving lists program and I'm stumbling over this error.



Note: .Multiple_Selection_List.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Multiple_Selection_List extends JFrame
{
private JList leftList;
private JList rightList;
private JButton moveButton;
private DefaultListModel model;
private DefaultListModel model2;

public Multiple_Selection_List()
{
super("Multiple Selection List");
setLayout(new FlowLayout());

model=new DefaultListModel();
model.addElement("Random");

model2 = new DefaultListModel();
model2.addElement("Random");

leftList = new JList(model);
leftList.setVisibleRowCount(3);
leftList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(leftList));

moveButton = new JButton("Move to right ------------->");
moveButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
rightList.setListData(leftList.getSelectedValuesList().toArray());
}
}
);

add(moveButton);

rightList=new JList(model2);
rightList.setVisibleRowCount(3);
rightList.setFixedCellWidth(100);
rightList.setFixedCellHeight(15);
rightList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(rightList));
}
}









share|improve this question
















I don't know where I'm going wrong but here's my code and I'm facing this error.
Basically I was watching Bucky Roberts' Tutorial on moving lists program and I'm stumbling over this error.



Note: .Multiple_Selection_List.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Multiple_Selection_List extends JFrame
{
private JList leftList;
private JList rightList;
private JButton moveButton;
private DefaultListModel model;
private DefaultListModel model2;

public Multiple_Selection_List()
{
super("Multiple Selection List");
setLayout(new FlowLayout());

model=new DefaultListModel();
model.addElement("Random");

model2 = new DefaultListModel();
model2.addElement("Random");

leftList = new JList(model);
leftList.setVisibleRowCount(3);
leftList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(leftList));

moveButton = new JButton("Move to right ------------->");
moveButton.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
rightList.setListData(leftList.getSelectedValuesList().toArray());
}
}
);

add(moveButton);

rightList=new JList(model2);
rightList.setVisibleRowCount(3);
rightList.setFixedCellWidth(100);
rightList.setFixedCellHeight(15);
rightList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
add(new JScrollPane(rightList));
}
}






java swing compiler-warnings jlist






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 12:34









Andrew Thompson

154k28163345




154k28163345










asked Nov 25 '18 at 12:12









Varun KhatriVarun Khatri

11




11








  • 2





    This is actually a warning and not an error, so you should still be able to run it. Have you compiled with this flag and gotten further details?

    – Joe C
    Nov 25 '18 at 12:17













  • I don,t actually know how to compile it further.. Do you mind if you could help me with that?

    – Varun Khatri
    Nov 25 '18 at 16:27






  • 1





    javac -Xlint:unchecked Multiple_Selection_List.java

    – Joe C
    Nov 25 '18 at 17:11














  • 2





    This is actually a warning and not an error, so you should still be able to run it. Have you compiled with this flag and gotten further details?

    – Joe C
    Nov 25 '18 at 12:17













  • I don,t actually know how to compile it further.. Do you mind if you could help me with that?

    – Varun Khatri
    Nov 25 '18 at 16:27






  • 1





    javac -Xlint:unchecked Multiple_Selection_List.java

    – Joe C
    Nov 25 '18 at 17:11








2




2





This is actually a warning and not an error, so you should still be able to run it. Have you compiled with this flag and gotten further details?

– Joe C
Nov 25 '18 at 12:17







This is actually a warning and not an error, so you should still be able to run it. Have you compiled with this flag and gotten further details?

– Joe C
Nov 25 '18 at 12:17















I don,t actually know how to compile it further.. Do you mind if you could help me with that?

– Varun Khatri
Nov 25 '18 at 16:27





I don,t actually know how to compile it further.. Do you mind if you could help me with that?

– Varun Khatri
Nov 25 '18 at 16:27




1




1





javac -Xlint:unchecked Multiple_Selection_List.java

– Joe C
Nov 25 '18 at 17:11





javac -Xlint:unchecked Multiple_Selection_List.java

– Joe C
Nov 25 '18 at 17:11












1 Answer
1






active

oldest

votes


















1














Since generics were added into Java back in JDK5 (I think) you should specify the class of the object that you want to add to the JList. Then the compiler can verify that you add the appropriate data to the JList.



You specify code with generics like:



model = new DefaultListModel<String>();
model.addElement("Random");
leftList = new JList<String>( model );


Now the compiler will verify you actually add a String object to the model and a model object containing strings to the JList.



Of course you also specify the class when you define the model and list variables.






share|improve this answer
























  • This also applies to rightList and model2.

    – NoDataFound
    Nov 25 '18 at 18:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467308%2fjlist-moving-lists-program%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Since generics were added into Java back in JDK5 (I think) you should specify the class of the object that you want to add to the JList. Then the compiler can verify that you add the appropriate data to the JList.



You specify code with generics like:



model = new DefaultListModel<String>();
model.addElement("Random");
leftList = new JList<String>( model );


Now the compiler will verify you actually add a String object to the model and a model object containing strings to the JList.



Of course you also specify the class when you define the model and list variables.






share|improve this answer
























  • This also applies to rightList and model2.

    – NoDataFound
    Nov 25 '18 at 18:37
















1














Since generics were added into Java back in JDK5 (I think) you should specify the class of the object that you want to add to the JList. Then the compiler can verify that you add the appropriate data to the JList.



You specify code with generics like:



model = new DefaultListModel<String>();
model.addElement("Random");
leftList = new JList<String>( model );


Now the compiler will verify you actually add a String object to the model and a model object containing strings to the JList.



Of course you also specify the class when you define the model and list variables.






share|improve this answer
























  • This also applies to rightList and model2.

    – NoDataFound
    Nov 25 '18 at 18:37














1












1








1







Since generics were added into Java back in JDK5 (I think) you should specify the class of the object that you want to add to the JList. Then the compiler can verify that you add the appropriate data to the JList.



You specify code with generics like:



model = new DefaultListModel<String>();
model.addElement("Random");
leftList = new JList<String>( model );


Now the compiler will verify you actually add a String object to the model and a model object containing strings to the JList.



Of course you also specify the class when you define the model and list variables.






share|improve this answer













Since generics were added into Java back in JDK5 (I think) you should specify the class of the object that you want to add to the JList. Then the compiler can verify that you add the appropriate data to the JList.



You specify code with generics like:



model = new DefaultListModel<String>();
model.addElement("Random");
leftList = new JList<String>( model );


Now the compiler will verify you actually add a String object to the model and a model object containing strings to the JList.



Of course you also specify the class when you define the model and list variables.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 25 '18 at 18:32









camickrcamickr

276k16127239




276k16127239













  • This also applies to rightList and model2.

    – NoDataFound
    Nov 25 '18 at 18:37



















  • This also applies to rightList and model2.

    – NoDataFound
    Nov 25 '18 at 18:37

















This also applies to rightList and model2.

– NoDataFound
Nov 25 '18 at 18:37





This also applies to rightList and model2.

– NoDataFound
Nov 25 '18 at 18:37




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467308%2fjlist-moving-lists-program%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno